HDU6342-2018ACM暑假多校联合训练4-1011-Problem K. Expression in Memories
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
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+* ?
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+*? .
If there are multiple answers, print any of them.
If it is impossible to find such an expression, print 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的更多相关文章
- 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 ...
- HDU6400-2018ACM暑假多校联合训练1004-Parentheses Matrix-构造
Parentheses Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- HDU6336-2018ACM暑假多校联合训练4-1005-Problem E. Matrix from Arrays-前缀和
题意是给了一种矩阵的生成方式 让你求两个左边之间的矩阵里面的数加起来的和(不是求矩阵的值) 没看标程之前硬撸写了160行 用了前缀和以后代码量缩短到原来的1/3 根据规律可以推导出这个矩阵是在不断重复 ...
- HDU6330-2018ACM暑假多校联合训练Problem L. Visual Cube
就是画个图啦 分三个平面去画orz #include <iostream> #include <cmath> #include <cstring> #include ...
- HDU6318-2018ACM暑假多校联合训练2-1010-Swaps and Inversions-树状数组
本题题意是,给你一个长度为n的序列,使用最少的操作把序列转换为从小到大的顺序,并输出操作数*min(x,y) 实质上是算出该序列中有多少逆序对,有归并排序和树状数组两种算法,由于数据之间的差值有点大, ...
- HDU6299-2018ACM暑假多校联合训练1002-Balanced Sequence
这个题的题意是给你n个字符串,认定()是一种平衡的串,两个以上连续的()()也是一种平衡的串,如果一对括号里面包含一个平衡的串,这个括号也被算在这个平衡的串之内, 如(()(()))是一个长度为8的平 ...
- HDU6298-2018ACM暑假多校联合训练1001-Maximum Multiple
题意大致是给你一个整数n,让你确定是否有三个正整数x,y,z既能被n整除,又能x+y+z=n,并使xyz最大 从中根据规律可以看出,只有被3或被4整除的数才能满足题目要求 被3整除的最大值为n^3/3 ...
- HDU6301-2018ACM暑假多校联合训练1004-Distinct Values
题意是一个长度为n的序列,给你m组区间(l,r),在这个区间里不能填入重复的数字,同时使整个序列字典序最小 同学用的优先队列,标程里使用的是贪心同时使用set维护答案序列 贪心是先采用pre数组来确定 ...
- HDU6308-2018ACM暑假多校联合训练1011-Time Zone
题目大意就是给你UTC-8时区的时间 让你求对应时区的时间 哇 这个题 看似简单,但是一开始怎么都过不了啊 同学用自己写的read过了,后来看了一下各位大佬说改成分钟随便过,就随便过了 Problem ...
随机推荐
- Windows修改MySQL用户root密码
MySQL是一个关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软 ...
- phpStudy启动失败时的解决方法 提示缺vc9运行库
问题描述: 问题产生原因分析: php5.3.5.4和apache都是用vc9编译,电脑必须安装vc9运行库才能运行. php5.5.5.6是vc11编译,如用php5.5.5.6必须安装vc11运行 ...
- flask系列一之环境搭建包安装
一,python的安装 (1)python的安装 (2)虚拟环境的配置 参考:http://www.cnblogs.com/bfwbfw/p/7995245.html 1,虚拟环境的建立 (1)使用p ...
- oracle——存储过程参数
oracle 存储过程类型: 1.in:输入类型,即由应用程序将数据传入oracle存储过程中:这种参数在存储过程中是只读参数,在存储过程中无法对该类型的参数进行修改: 2.out:输出参数,是在存储 ...
- python利用utf-8编码判断中文字符
下面这个小工具包含了 判断unicode是否是汉字,数字,英文,或者其他字符. 全角符号转半角符号. unicode字符串归一化等工作. 还有一个能处理多音字的汉字转拼音的程序,还在整理中. #!/u ...
- 【总结整理】pv、uv
1.pv的全称是page view,译为页面浏览量或点击量,通常是衡量一个网站甚至一条网络新闻的指标.用户每次对网站中的一个页面的请求或访问均被记录1个PV,用户对同一页面的多次访问,pv累计.例如, ...
- jQuery div鼠标移动效果
<head runat="server"> <meta http-equiv="Content-Type" content="tex ...
- 【转】LVS负载均衡之session解决方案 持久连接
原文地址:http://minux.blog.51cto.com/8994862/1744761 1. 持久连接是什么? 1.1 在LVS中,持久连接是为了用来保证当来自同一个用户的请求时能够定位到同 ...
- ssh时传递环境变量
设置要传递的变量: -o SendEnv=Varname 但是不是每个都能传,受服务器上sshd_config里的下面两个选项的控制: AcceptEnv and PermitUserEnvironm ...
- Entity Framework 6.0 Tutorials(1):Introduction
以下系统文章为EF6.0知识的介绍,本章是第一篇 原文地址:http://www.entityframeworktutorial.net/entityframework6/introduction.a ...