之前在华工赛见过的一道简单的模拟,用map轻松干掉。为了精确,要全程用整型比较。轻松1y~
代码如下:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <map> using namespace std; map<string, int> val; int con(char *str) {
int a, b;
sscanf(str, "%d.%d", &a, &b);
return a * + b;
} bool check(int a, int b, char *p) {
if (!strcmp(p, "=")) return a == b;
if (!strcmp(p, "<=")) return a <= b;
if (!strcmp(p, ">=")) return a >= b;
if (!strcmp(p, "<")) return a < b;
if (!strcmp(p, ">")) return a > b;
return false;
} int main() {
int n, m;
char buf[][];
while (cin >> n >> m) {
for (int i = ; i < n; i++) {
for (int i = ; i < ; i++) cin >> buf[i];
val[buf[]] = con(buf[]);
}
for (int cas = ; cas <= m; cas++) {
int sum = ;
while (true) {
cin >> buf[];
sum += val[buf[]];
cin >> buf[];
if (buf[][] != '+') break;
}
int x;
cin >> x;
cout << "Guess #" << cas << " was " << (check(sum, x * , buf[]) ? "correct." : "incorrect.") << endl;
}
}
return ;
}
——written by Lyon