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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| #include <bits/stdc++.h> using namespace std; int ipt[10]; bool used[10]; void f(int a, char b, int c) { int x = 0, z = 0, pa = a, pc = c; if (a == 0) x = ipt[a]; else while (a) { int t = a % 10; x += ipt[t] * pow(10, z); z++; a /= 10; }
cout << pa;
int y = 0; z = 0; if (c == 0) y = ipt[a]; while (c) { int t = c % 10; y += ipt[t] * pow(10, z); z++; c /= 10; } int preans; if (b == '+') preans = x + y; if (b == '*') preans = x * y; if (b == '-') preans = x - y; if (b == '/') preans = x / y;
cout << b; cout << pc;
int ans = 0; z = 0; if (preans == 0) y = ipt[a]; while (preans) { int t = preans % 10; ans += ipt[t] * pow(10, z); z++; preans /= 10; } cout << "=" << ans << endl; } void show() { for (int i = 0; i <= 9; i++) if (ipt[i] != i) cout << i << " " << ipt[i] << endl; system("pause"); exit(0); } int main() { srand((unsigned)time(NULL)); cout << "the meanings of some numbers have been changed, enter expressions to find changes" << endl; cout << "for example, if 2 turns to be 5 and 5 turns to be 2,then 2*2=52" << endl; cout << "to increase difficulty, you could only use \"A+B\" or \"A*B\"" << endl; int n; cout << "input the number of changes from 0 to 10" << endl; cin >> n; memset(ipt, -1, sizeof(ipt)); for (int p = 0; p < n;) { int a = rand()%10, b = rand()%10; if (a != b && !used[a]) { p++; used[a] = 1; ipt[a] = b; } } for (int i = 0; i <= 9; i++) if (ipt[i] == -1) ipt[i] = i; int cnt=0; while (1) { again:; cnt++; cout << "input expression, pay attention that negative results will be replaced by 0" << endl; int a, c;char b; cin>>a>>b>>c; f(a, b, c); cout << "have an answer? input all changes, or input -1 to continue, or input -2 to show answer" << endl; int flag = 0; for (int i = 1; i <= n; i++) { int in, out; cin >> in; if (in == -1) goto again; if (in == -2) show(); cin >> out; if (ipt[in] == out) flag++; } if (flag == n) { cout << "well done, you have finished it in " << cnt << " steps" <<endl; system("pause"); return 0; } else cout << "WA" << endl; } }
|