Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
Special Judge


Problem Description
Kazari remembered that she had an expression s with a character in 0123456789+* ?
 

 

Input
The first line of the input contains an integer s will be in 0123456789+*? .
 

 

Output
For each test case, print a string 0 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

先考虑运算符不行的情况再考虑前导0的情况 

 

AC代码
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
string s;
vector<string> e;
bool iso( char c ) {
    if( c == '+' || c == '*' ) {
        return true;
    }
    return false;
}
int main() {
    ll T;
    cin >> T;
    while( T -- ) {
        cin >> s;
        bool flag = true;
        for( ll i = 0; i < s.length(); i ++ ) {
            if( ( i == 0 || i == s.length()-1 ) && iso(s[i]) ) {
                flag = false;
                break;
            }
            if( i < s.length()-1 ) {
                if( iso(s[i]) && iso(s[i+1]) ) {
                    flag = false;
                    break;
                }
            }
            if( s[i] == '?' ) {
                if( s[i-1] == '0' && ( i-2 < 0 || iso(s[i-2])  ) && !iso(s[i+1]) ) {
                    s[i] = '+';
                } else {
                    s[i] = '1';
                }
            }
        }
        //debug(s);
        e.clear();
        string t = "";
        for( ll i = 0; i < s.length(); i ++ ) {
            if( iso(s[i]) || i == s.length()-1 ) {
                if( i == s.length()-1 ) {
                    t += s[i];
                }
                e.push_back(t);
                t = "";
            } else {
                t += s[i];
            }
        }
        for( ll i = 0; i < e.size(); i ++ ) {
            //cout << e[i] << endl;
            if( e[i][0] == '0' && e[i].length() > 1 ) {
                flag = false;
                break;
            }
        }
        if( flag ) {
            cout << s << endl;
        } else {
            cout << "IMPOSSIBLE" << endl;
        }
    }
    return 0 ;
}

  

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2021-09-14
  • 2021-11-24
  • 2021-09-10
  • 2022-03-05
  • 2021-05-29
  • 2021-08-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案