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 ...
随机推荐
- shell程序设计小知识
一.用户登陆进入系统后的系统环境变量:$HOME 使用者自己的目录$PATH 执行命令时所搜寻的目录$TZ 时区$MAILCHECK 每隔多少秒检查是否有新的信件$PS1 在命令列时的提示号$PS2 ...
- C#基础笔记 转自wojiushigelg
笔记如下: 概念:.net与c# .net/dontnet:一般指.net framework框架,一种平台,一种技术 c#(charp):一种编程语言,可以开发基于.net的应用. *java既是一 ...
- CSS代码优化(转载)
要点1:css代码优化作用与意义 1.减少占用网页字节.在同等条件下缩短浏览器下载css代码时间,相当于加快网页打开速度:2.便于维护.简化和标准化css代码让css代码减少,便于日后维护:3.让自己 ...
- WPF画箭头
简介 参考Using WPF to Visualize a Graph with Circular Dependencies的基础上写了一个WPF画箭头的库. 效果图如下: 使用的XAML代码如下: ...
- Spring学习笔记:Spring整合Mybatis(mybatis-spring.jar)(二:mybatis整合spring)
http://blog.csdn.net/qq598535550/article/details/51703190 二.Spring整合mybatis其实是在mybatis的基础上实现Spring框架 ...
- HttpResponse Entity的处理(将字符数组转为JSON)
1.问题背景 调用高德的IP地址查询接口,获取的返回值为字符串数组(如下); 因为这里只是纯字符串,并不是真正的数组,无法直接取值,所以想到看能不能转为数组或者JSON再进行取值. 2.解决: 通过在 ...
- gradle -v不是外部命令, 内部命令,或批处理文件
安装完gradle并且配置了环境变量之后,使用windos+R,cmd 进入Dos命令gradle -v检测版本号出现了: 1 --首先找到gradle文件所在目录 一般是在C:\Users\su\. ...
- Spring系列之Alias标签的解析与使用
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- css多行本文垂直集中
<div style="display:table;height:400px;"> <span style="display:table-cell;ve ...
- Python基础-I/O模型
一.I/O模型 IO在计算机中指Input/Output,也就是输入和输出.由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接 ...