2018 Multi-University Training Contest 4 Problem K. Expression in Memories 【模拟】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6342
Problem K. Expression in Memories
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2150 Accepted Submission(s): 772
Special Judge
Definition of expression is given below in Backus–Naur form.
<expression> ::= <number> | <expression> <operator> <number>
<operator> ::= "+" | "*"
<number> ::= "0" | <non-zero-digit> <digits>
<digits> ::= "" | <digits> <digit>
<digit> ::= "0" | <non-zero-digit>
<non-zero-digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
For example, `1*1+1`, `0+8+17` are valid expressions, while +1+1, +1*+1, 01+001 are not.
Though s0 has been lost in the past few years, it is still in her memories.
She remembers several corresponding characters while others are represented as question marks.
Could you help Kazari to find a possible valid expression s0 according to her memories, represented as s, by replacing each question mark in s with a character in 0123456789+* ?
Input
Each test case consists of one line with a string s (1≤|s|≤500,∑|s|≤105).
It is guaranteed that each character of s will be in 0123456789+*? .
Output
If there are multiple answers, print any of them.
If it is impossible to find such an expression, print IMPOSSIBLE.
Sample Input
Sample Output
题意概括:
给一串表达式(可能完整可能不完整),表达式只含有 ‘+’ 和 ‘ * ’ 两种运算,数字为 0~9;
如果不完整(含' ? '), 则补充完整。
若表达式本身非法或者无法补充成为一个合法表达式,则输出“IMPOSSIBLE”
解题思路:
很明显 “ ?” 只有在 0?的情况下需要变成 ‘+’ 或者‘*’; 其他情况都把 “ ?”变成 非0的数字即可。
判断表达式是否合法: 是否出现 0111 或者 ++ 或者 *+ 这类的情况即可。
AC code:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const LL MOD = 1e9+;
const int MAXN = ;
char str[MAXN];
//char ans[MAXN]; int main()
{
int T_case;
scanf("%d", &T_case);
while(T_case--){
scanf("%s", str);
int len = strlen(str);
bool flag = true; for(int i = ; i < len; i++){
if(str[i] == '+' || str[i] == '*'){
if(i == || i == len-){
flag = false;
break;
}
else if(str[i+] == '+' || str[i+] == '*'){
flag = false;
break;
}
}
else if(str[i] == ''){
if(i == || str[i-] == '+' || str[i-] == '*'){
if(i < len- && str[i+] >= '' && str[i+] <= ''){
flag = false;
break;
}
else if(i < len- && str[i+] == '?'){
str[i+] = '+';
}
}
}
else if(str[i] == '?'){
str[i] = '';
}
} if(flag) printf("%s\n", str);
else puts("IMPOSSIBLE");
}
return ;
}
2018 Multi-University Training Contest 4 Problem K. Expression in Memories 【模拟】的更多相关文章
- 杭电多校第四场 Problem K. Expression in Memories 思维模拟
Problem K. Expression in Memories Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262 ...
- HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)
6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ...
- HDU6342-2018ACM暑假多校联合训练4-1011-Problem K. Expression in Memories
Problem K. Expression in Memories Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262 ...
- HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 【单调队列优化】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6319 Problem A. Ascending Rating Time Limit: 10000/500 ...
- 2018 Multi-University Training Contest 4 Problem J. Let Sudoku Rotate 【DFS+剪枝+矩阵旋转】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6341 Problem J. Let Sudoku Rotate Time Limit: 2000/100 ...
- 2018 Multi-University Training Contest 4 Problem E. Matrix from Arrays 【打表+二维前缀和】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6336 Problem E. Matrix from Arrays Time Limit: 4000/20 ...
- 2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Problem L. Graph Theory Homework Time Limit: 2000 ...
- 2018 Multi-University Training Contest 4 Problem B. Harvest of Apples 【莫队+排列组合+逆元预处理技巧】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 Problem B. Harvest of Apples Time Limit: 4000/200 ...
- 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...
随机推荐
- Firebird 用查询结果集更新数据,merge
Merge语法: MERGE INTO target [[AS] target-alias ] USING source [[AS] source-alias ] ON join-condition ...
- 自动生成数据库字典(sql2008) 转自 飘渺の云海
每次做项目的时候都要做数据字典,这种重复的工作实在很是痛苦,于是广找资料,终于完成了自动生成数据库字典的工作,废话少说,上代码. 截取一部分图片: 存储过程: SET ANSI_NULLS ON GO ...
- Java API 之 Annotation功能
JDK1.5开始增加了Annotation功能,该功能可用于: 1.类: 2.构造方法: 3.成员变量: 4.方法 5.参数 等的声明: 该功能并不影响程序的运行,但是会对编译器警告等辅助工具产生影响 ...
- Java 基础(7)——运算符
学完基础的变量常量等知识.再往后和变量常量紧密相关的当然是加减乘除等等运算方法了~(当然加减乘除也只是一部分) 首先按照运算过程参与的元素,把运算符号简单粗暴的分为一元运算符.二元运算符.三元运算符等 ...
- hdu1385 最短路字典序
http://blog.csdn.net/ice_crazy/article/details/7785111 http://blog.csdn.net/shuangde800/article/deta ...
- Axios介绍和使用
一.介绍 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. 官方资料和介绍 从浏览器中创建 XMLHttpRequests 从 node.js 创建 h ...
- iview中upload组件上传图片,跨域
前提:先前开发了一个A项目,A项目中有一套上传图片的接口,现在开发B项目. B项目开发中用iview中的upload组件上传图片,用到了A项目中上传接口,爬坑经历 1.涉及到了跨域解决:后台配置一下文 ...
- HTML 简单日历制作方法
新手一枚,不会写什么高大上的博文,一些平时做的小练习,献丑 <!doctype html> <html> <head> <meta charset=" ...
- 项目经验:GIS<MapWinGIS>建模第三天
记录下GIS工程进展
- visual studio 2013的C++开发环境不错--vs2013安装试用手记
原文:http://blog.csdn.net/haoyujie/article/details/24370189 从visual studio 体系,最后一次对C++实现了大的改进,那还是vs 7. ...