-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphep_toan_co_ban.cpp
More file actions
73 lines (71 loc) · 1.6 KB
/
phep_toan_co_ban.cpp
File metadata and controls
73 lines (71 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define sz size()
#define ll long long
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FORD(i, a, b) for(int i = a; i > b; --i)
#define faster() ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define vll vector<ll>
#define endl '\n'
string s;
vector<int> pos;
int ok = 0;
int check(string str){
int a = (str[0]-'0')*10+(str[1]-'0');
int b = (str[5]-'0')*10+(str[6]-'0');
int c = (str[10]-'0')*10+(str[11]-'0');
char x = str[3];
//cout << a << " " << b << " " << c << " " << x << endl;
if(x == '+' && a + b == c) return 1;
if(x == '-' && a - b == c) return 1;
if(x == '*' && a * b == c) return 1;
if(x == '/' && a % b == 0 && a / b == c) return 1;
return 0;
}
void ql(int i, string str){
if(ok) return;
if(i == pos.size()){
if(check(str)){
cout << str << endl;
ok = 1;
}
return;
}
if(pos[i] == 3){
string tmp = str;
tmp[3] = '+'; ql(i+1, tmp);
tmp[3] = '-'; ql(i+1, tmp);
tmp[3] = '*'; ql(i+1, tmp);
tmp[3] = '/'; ql(i+1, tmp);
}
else{
char first = '0';
if(pos[i] == 0 || pos[i] == 5 || pos[i] == 10)
first = '1';
for(char j = first; j <= '9'; j++){
string tmp = str;
tmp[pos[i]] = char(j);
ql(i+1, tmp);
}
}
}
void solve(){
scanf("\n");
getline(cin, s);
pos.clear();
ok = 0;
for(int i = 0; i < s.length(); i++){
if(s[i] == '?') pos.pb(i);
}
ql(0, s);
if(!ok) cout << "WRONG PROBLEM!\n";
}
int main(){
int t; cin >> t;
while(t--)
solve();
}