K

 Sample Input

5
?????
0+0+0
?+*??
?0+?0
?0+0?

Sample Output

11111
0+0+0
IMPOSSIBLE
10+10
IMPOSSIBLE

判断字符串是否符合格式
分为数字、运算符、问号考虑,注意首尾位置特殊情况
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3  
 4 int main()
 5 {
 6     int t;
 7     char s[1005];
 8     cin >> t;
 9     for(int T = 0;T<t;T++)
10     {
11         cin >> s;
12         for(int i = 0;i < strlen(s);i++)
13         {
14             if(s[i] == '?')
15             {
16                 if(!isdigit(s[i-2]) && s[i-1] == '0' )
17                     s[i] = '+';
18                 else
19                     s[i] = '1';
20             }
21         }
22         int flag = 0;
23         for(int i = 0; i < strlen(s); i++)
24         {
25             if(!isdigit(s[i]))
26             {
27                 if( !isdigit(s[i+1]) )
28                     flag = 1;
29             }
30             else if( s[i] == '0' )
31             {
32                 if( !isdigit(s[i-1]) && isdigit(s[i+1]) )
33                     flag = 1;
34             }
35         }
36         if(!isdigit(s[0]) || !isdigit(s[strlen(s)-1]))
37             flag = 1;
38         if(flag)
39         cout << "IMPOSSIBLE
";
40         else 
41             cout << s << endl;
42     }
43     return 0;
44 }

作者:YukiRinLL

出处:YukiRinLL的博客--https://www.cnblogs.com/SutsuharaYuki/

您的支持是对博主最大的鼓励,感谢您的认真阅读。

本文版权归作者所有,欢迎转载,但请保留该声明。

原文地址:https://www.cnblogs.com/SutsuharaYuki/p/11301348.html