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 ...
随机推荐
- PHP 取网页变量
$_POST["test"]; $_GET["test"];isset(); if(isset($_GET["yyuid"]))
- sendMail在centos下的安装
一.sendEmail介绍 SendEmail is a lightweight, command line SMTP email client. If you have the need to ...
- ATL向控件添加私有属性-成员变量
https://msdn.microsoft.com/zh-cn/library/cc451389(v=vs.71).aspx ------------------------------------ ...
- Subscript & Inheritance
[Subscript] 1.subscript的定义: 2.Subscript的使用: 3.可以定义多维subscript: 多维Subscript的使用: [Inheritance] 1.overr ...
- 深入剖析SolrCloud(三)
作者:洞庭散人 出处:http://phinecos.cnblogs.com/ 本博客遵从Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由 ...
- 由于挂载的nfs存储目录掉下线,导致创建VM时,无法创建
具体错误,如下截图 重新挂载存储后,在创建VM,将成功
- 面试题:cook和session
1.首先,Cookie与Session存在的目的是什么? 答:二者都是为了保持客户端访问用户与后台服务器的交互状态,之所以为了保持这种状态,一是为了方便一些业务的实现,另一方面就是为了简化后台服务端的 ...
- dpdk中kni模块
一,什么是kni,为什么要有kni Kni(Kernel NIC Interface)内核网卡接口,是DPDK允许用户态和内核态交换报文的解决方案,模拟了一个虚拟的网口,提供dpdk的应用程序和lin ...
- wordpress+lnmp出现 404 Not Found nginx
在本地使用Apache,因此进行重写规则是.htaccess文件,但在Nginx服务器中此文件不起作用. 只需在网站的虚拟机配置文件中添加如下 location / { if (-f $request ...
- Capturing ASP.NET Application Startup Exceptions
It has become common practice to perform tasks during an ASP.NET applications start up process. Thes ...