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这个错误

 #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std; char ch[];
int ch1[];
int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--)
{
cin >> ch;
bool flag = ;
for (int i = ; i < strlen(ch); i++)
{
if (i > && (ch[i - ] == '+' || ch[i - ] == '*') && ch[i - ] == '' && ch[i] == '?')
ch[i] = '+';
if (i == && ch[i] == '?' && ch[i - ] == '')
ch[i] = '+';
else if(ch[i] == '?')
ch[i] = '';
}
if (ch[strlen(ch) - ] == '+' || ch[strlen(ch) - ] == '*' || ch[] == '+' || ch[] == '*')
flag = ;
else
{
for (int i = ; i < strlen(ch); i++)
{
if (i == && ch[i - ] == '' && ch[i] >= '' && ch[i] <= '')
flag = ;
else if (i > && ch[i - ] == '' && (ch[i - ] == '+' || ch[i - ] == '*') && ch[i] >= '' && ch[i] <= '')
flag = ;
else if ((ch[i - ] == '+' || ch[i - ] == '*') && (ch[i] == '+' || ch[i] == '*'))
flag = ;
}
}
if(flag)
cout << "IMPOSSIBLE" << endl;
else
cout << ch << endl;
}
return ;
}

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. burpsuite扫描web目录

    1.进行抓包 2.将其发送到lntruder 3.使用替换脚本替换掉/ 4.替换 5.替换结果 6.将多余的$$删除,在/后面添加$$    //$$就是payload 7.测试结果  替换脚本代码: ...

  2. linux 下安装mysql-5.7.16

    1.解压tar -xvf mysql的包 tar -xvf mysql-5.7.16-1.el6.x86_64.rpm-bundle.tar(mysql 官网中即可找到) 2.查看是否需要卸载安装时候 ...

  3. springboot整合redis单机及集群

    一.单机配置 properties配置 #单机redis spring.redis.host=127.0.0.1 spring.redis.port=6379 spring.redis.passwor ...

  4. 非常详细的ok6410的linux系统移植…

    目录 Linux 3.3.5系统移植 2 LED驱动移植 8 按键驱动移植 9 LCD驱动移植 11 DM9000网卡驱动移植 14 搭建NFS网络文件系统 25 移植触摸屏驱动 38 移植Qt4.8 ...

  5. 4-2 线程安全性-原子性-atomic-2

    AtomicReference和AtomicLong.AtomicInteger很像,方法也基本上是一样的,然后我们通过引用Integer来做一个简单的例子. com.mmall.concurrenc ...

  6. SpringBoot27 JDK动态代理详解、获取指定的类类型、动态注册Bean、接口调用框架

    1 JDK动态代理详解 静态代理.JDK动态代理.Cglib动态代理的简单实现方式和区别请参见我的另外一篇博文. 1.1 JDK代理的基本步骤 >通过实现InvocationHandler接口来 ...

  7. Docker学习之路(一)

    容器简介 管理程序虚拟化(hypervisor virtualization, HV)是通过中间虚拟运行于物理硬件之上.而容器是直接运行在操作系统内核之上用户空间.因此,容器虚拟化运行也成为“操作系统 ...

  8. Luogu 4438 [HNOI/AHOI2018]道路

    $dp$. 这道题最关键的是这句话: 跳出思维局限大胆设状态,设$f_{x, i, j}$表示从$x$到根要经过$i$条公路,$j$条铁路的代价,那么对于一个叶子结点,有$f_{x, i, j} = ...

  9. oracle数据库创建表

    实际工作中,在数据库中创建表是经常会用到的.我们今天呢?主要给大家来分享一下在数据库如何通过sql语句去创建表.其实,创建表很简单,只需要把数据库的数据类型和约束搞清楚就可以了,其他的就好说了.接下来 ...

  10. Detailed ASP.NET MVC Pipeline

    Posted By : Shailendra Chauhan, 27 Jan 2014 P.NET MVC is an open source framework built on the top o ...