Problem K. Expression in Memories

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
Special Judge

Problem Description
Kazari remembered that she had an expression s0 before.
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
The first line of the input contains an integer T denoting the number of test cases.
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
For each test case, print a string s0 representing a possible valid expression.
If there are multiple answers, print any of them.
If it is impossible to find such an expression, print IMPOSSIBLE.
 
Sample Input
5
?????
0+0+0
?+*??
?0+?0
?0+0?
 
Sample Output
11111
0+0+0
IMPOSSIBLE
10+10
IMPOSSIBLE

题意就是让你在?里添加上合适的1或者+,并判断该式子是否合法(语序有一点错误)

注意在类似 +0? 的情况下, ? 须被替换为 + 或 * ,其余情况直接将 ? 替换为非零数字就好。替换完成后判断一下是否合法。

                                                     ———HDU题解

全靠队友一条大腿,当时WA到死都没找到0??1这个错误

  1. #include<iostream>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. char ch[];
  7. int ch1[];
  8. int main()
  9. {
  10. ios::sync_with_stdio(false);
  11. int t;
  12. cin >> t;
  13. while (t--)
  14. {
  15. cin >> ch;
  16. bool flag = ;
  17. for (int i = ; i < strlen(ch); i++)
  18. {
  19. if (i > && (ch[i - ] == '+' || ch[i - ] == '*') && ch[i - ] == '' && ch[i] == '?')
  20. ch[i] = '+';
  21. if (i == && ch[i] == '?' && ch[i - ] == '')
  22. ch[i] = '+';
  23. else if(ch[i] == '?')
  24. ch[i] = '';
  25. }
  26. if (ch[strlen(ch) - ] == '+' || ch[strlen(ch) - ] == '*' || ch[] == '+' || ch[] == '*')
  27. flag = ;
  28. else
  29. {
  30. for (int i = ; i < strlen(ch); i++)
  31. {
  32. if (i == && ch[i - ] == '' && ch[i] >= '' && ch[i] <= '')
  33. flag = ;
  34. else if (i > && ch[i - ] == '' && (ch[i - ] == '+' || ch[i - ] == '*') && ch[i] >= '' && ch[i] <= '')
  35. flag = ;
  36. else if ((ch[i - ] == '+' || ch[i - ] == '*') && (ch[i] == '+' || ch[i] == '*'))
  37. flag = ;
  38. }
  39. }
  40. if(flag)
  41. cout << "IMPOSSIBLE" << endl;
  42. else
  43. cout << ch << endl;
  44. }
  45. return ;
  46. }

HDU6342-2018ACM暑假多校联合训练4-1011-Problem K. Expression in Memories的更多相关文章

  1. HDU6333-2018ACM暑假多校联合训练1002-Harvest of Apples-莫队+费马小定理

    题意很简单啦,求S(n,m)的值 通过打表我们可以知道 S(n + 1, m) = S(n, m) * 2 - C(n, m); S(n - 1, m) = (S(n, m) + C(n - 1, m ...

  2. HDU6400-2018ACM暑假多校联合训练1004-Parentheses Matrix-构造

    Parentheses Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  3. HDU6336-2018ACM暑假多校联合训练4-1005-Problem E. Matrix from Arrays-前缀和

    题意是给了一种矩阵的生成方式 让你求两个左边之间的矩阵里面的数加起来的和(不是求矩阵的值) 没看标程之前硬撸写了160行 用了前缀和以后代码量缩短到原来的1/3 根据规律可以推导出这个矩阵是在不断重复 ...

  4. HDU6330-2018ACM暑假多校联合训练Problem L. Visual Cube

    就是画个图啦 分三个平面去画orz #include <iostream> #include <cmath> #include <cstring> #include ...

  5. HDU6318-2018ACM暑假多校联合训练2-1010-Swaps and Inversions-树状数组

    本题题意是,给你一个长度为n的序列,使用最少的操作把序列转换为从小到大的顺序,并输出操作数*min(x,y) 实质上是算出该序列中有多少逆序对,有归并排序和树状数组两种算法,由于数据之间的差值有点大, ...

  6. HDU6299-2018ACM暑假多校联合训练1002-Balanced Sequence

    这个题的题意是给你n个字符串,认定()是一种平衡的串,两个以上连续的()()也是一种平衡的串,如果一对括号里面包含一个平衡的串,这个括号也被算在这个平衡的串之内, 如(()(()))是一个长度为8的平 ...

  7. HDU6298-2018ACM暑假多校联合训练1001-Maximum Multiple

    题意大致是给你一个整数n,让你确定是否有三个正整数x,y,z既能被n整除,又能x+y+z=n,并使xyz最大 从中根据规律可以看出,只有被3或被4整除的数才能满足题目要求 被3整除的最大值为n^3/3 ...

  8. HDU6301-2018ACM暑假多校联合训练1004-Distinct Values

    题意是一个长度为n的序列,给你m组区间(l,r),在这个区间里不能填入重复的数字,同时使整个序列字典序最小 同学用的优先队列,标程里使用的是贪心同时使用set维护答案序列 贪心是先采用pre数组来确定 ...

  9. HDU6308-2018ACM暑假多校联合训练1011-Time Zone

    题目大意就是给你UTC-8时区的时间 让你求对应时区的时间 哇 这个题 看似简单,但是一开始怎么都过不了啊 同学用自己写的read过了,后来看了一下各位大佬说改成分钟随便过,就随便过了 Problem ...

随机推荐

  1. in not in 和 null , in 判断范围中可以包含null,而not in判断不能包括null

    oracle中,任何字符串与null比较得到的结果都是null,而 oracle的判断条件为null时就退出判断(?) 因此判断某个字符串是否在一个集合中时,not in 和 in的结果完全不一样,如 ...

  2. Python3.x 常用的新特性

    Python3.x 常用的新特性 print() 是函数,不是一个语句 raw_input()输入函数,改为 input() Python 3 对文本和二进制数据做了更为清晰的区分. 文本由unico ...

  3. Rest Framework 认证源码流程

    一.请求到来之后,都要先执行dispatch方法,dispatch方法方法根据请求方式的不同触发get/post/put/delete等方法 注意,APIView中的dispatch方法有很多的功能 ...

  4. C#统计网站访问总人数和当前在线人数 Application

    一.打开vitualstudio2010,新建一个网站,然后添加新项,新建一个login.aspx和index.aspx页面.再添加新项,选择全局应用程序类,该页面为Global.asax. 第一步: ...

  5. struts2结合axis开发webservice

    第一步:引入axis的依赖jar包  第二步:修改web.xml文件  <listener> <listener-class>org.apache.axis.transport ...

  6. Hadoop之HDFS(三)HDFS的JAVA API操作

    HDFS的JAVA API操作 HDFS 在生产应用中主要是客户端的开发,其核心步骤是从 HDFS 提供的 api中构造一个 HDFS 的访问客户端对象,然后通过该客户端对象操作(增删改查)HDFS ...

  7. 高性能的城市定位API接口

    如果不需要精准的定位,还有一种通过IP地址获取当前城市的方法,采用新浪的api接口. <script src="http://int.dpool.sina.com.cn/iplooku ...

  8. CSS 内容生成

    原文地址:http://www.zhangxinxu.com/wordpress/?p=739 一.哗啦哗啦的简介 zxx://这里“哗啦哗啦”的作用是为了渲染一种氛围.content属性早在CSS2 ...

  9. mongo_2 $in 和 $all 区别

    in 只需满足( )内的某一个值即可, 而$all 必须满足[ ]内的所有值, > db.table1.find({}); { "_id" : ObjectId(" ...

  10. jQuery 对象和 json 之间的转换

    JSON.parse() json 转换成 对象 JSON.stringify() 对象转换成json 想问下广大网友大神 js 里面有数组转换或者转换成数组的函数么?小弟等--