您的位置:首页 > 其它

UVA 11489 Integer Game——博弈

2018-03-09 14:07 435 查看
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1005;
char s[maxn];
int T, n;
int main() {
//freopen("out.txt", "w", stdout);
scanf("%d", &T);
for (int kase = 1; kase <= T; kase++) {
cin >> s;
n = strlen(s);
if (n == 1) {
printf("Case %d: S\n", kase);
continue;
}
int sum = 0, cnt = 0;
for (int i = 0; i < n; i++) {
sum += s[i]-'0';
if ((s[i]-'0') % 3 == 0) cnt++;
}
if (sum % 3 == 0) {
if (cnt % 2 == 0) printf("Case %d: T\n", kase);
else printf("Case %d: S\n", kase);
continue;
}
else {
bool ok = false;
for (int i = 0; i < n; i++) {
if ((sum-s[i]+'0') % 3 == 0) { ok = true; break; }
}
if (!ok) {
printf("Case %d: T\n", kase);
continue;
}
else {
if (cnt % 2 == 0) printf("Case %d: S\n", kase);
else printf("Case %d: T\n", kase);
continue;
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: