HDU6342 杭电多校第四场 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): 924    Accepted Submission(s): 354
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

 

 

Source

2018 Multi-University Training Contest 4

 

【题意】:给你一个字符串,问你能否构成一个合法的表达式,可以的话输出其中之一,不可以的话输出IMPOSSIBLE,表达式由数字,+,*组成

 

【思路】:可能最近脑子比较混,一道思维题,首先考虑能不能构成数字符号数字,再考虑有没有前导0的情况,比赛的时候思维十分混乱,一堆Bug.....

 

AC代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main ()
{
	int t;
	char s[509];
	scanf("%d",&t);
	while (t--){
		memset(s,0,sizeof(s));
		scanf("%s",s+1);
		int len = strlen(s+1);
		int vis = 0;
		if ((s[1] < '0' || s[1] > '9') && s[1] != '?') {
			printf("IMPOSSIBLE\n");
			continue;
		}
		if ((s[len] < '0' || s[len] > '9') && s[len] != '?') {
			printf("IMPOSSIBLE\n");
			continue;
		}
		if (((s[len-2] < '0' || s[len-2] > '9') && s[len-2] != '?')&&s[len-1] == '0'){
			printf("IMPOSSIBLE\n");
			continue;
		}
		if (s[1] == '0') vis = 1;
		if (s[1] == '?') s[1] = '1';
		int flag = 0;
		int k = 0;
		for (int i=  2; i <= len; i++){
			if (flag){
				if (s[i] == '0') vis = 1,flag = 0;
				else vis = 0,flag = 0;
				if ((s[i] < '0' || s[i] > '9') && s[i] != '?') {
					printf("IMPOSSIBLE\n");
					k = 1;
					break;
				}
				if (s[i] == '?'){
					s[i] = '1';
				}
				continue;
			}
			if (vis) {
				if (s[i] >= '0' && s[i] <= '9') {
					printf("IMPOSSIBLE\n");
					k = 1;
					break;
				}
				else if (s[i] == '?' && s[i+1] != '+' && s[i+1] != '*'){
					s[i] = '+';
					flag = 1;
					vis = 0;
				}
				else if (s[i] == '?' && (s[i+1] != '+' || s[i+1] != '*')){
					printf("IMPOSSIBLE\n");
					k = 1;
					break;
				}
				else vis = 0;
			}
			if ((s[i] < '0' || s[i] > '9') && s[i] != '?') {
				flag = 1;
			}
			else{
				flag = 0;
				if (s[i] == '?')
					s[i] = '1';
			}
		}
		if ((s[len] < '0' || s[len] > '9') && s[len] != '?') {
			printf("IMPOSSIBLE\n");
			continue;
		}
		if (!k){
			for (int i =1 ; i <= len; i++) printf("%c",s[i]);
			printf("\n");
		}
	}
}

 

航拍图像类别实例分割数据集 一、基础信息 • 数据集名称:航拍图像类别实例分割数据集 • 图片数量: 训练集:1283张图片 验证集:416张图片 总计:1699张航拍图片 • 训练集:1283张图片 • 验证集:416张图片 • 总计:1699张航拍图片 • 分类类别: 桥梁(Bridge) 田径场(GroundTrackField) 港口(Harbor) 直升机(Helicopter) 大型车辆(LargeVehicle) 环岛(Roundabout) 小型车辆(SmallVehicle) 足球场(Soccerballfield) 游泳池(Swimmingpool) 棒球场(baseballdiamond) 篮球场(basketballcourt) 飞机(plane) 船只(ship) 储罐(storagetank) 网球场(tennis_court) • 桥梁(Bridge) • 田径场(GroundTrackField) • 港口(Harbor) • 直升机(Helicopter) • 大型车辆(LargeVehicle) • 环岛(Roundabout) • 小型车辆(SmallVehicle) • 足球场(Soccerballfield) • 游泳池(Swimmingpool) • 棒球场(baseballdiamond) • 篮球场(basketballcourt) • 飞机(plane) • 船只(ship) • 储罐(storagetank) • 网球场(tennis_court) • 标注格式:YOLO格式,包含实例分割的边形坐标,适用于实例分割任务。 • 数据格式:航拍图像数据。 二、适用场景 • 航拍图像分析系统开发:数据集支持实例分割任务,帮助构建能够自动识别和分割航拍图像中各种物体的AI模型,用于地理信息系统、环境监测等。 • 城市
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值