UVa 11489 - Integer Game

先手的人优先选取与总和对三求余的数相同的数字,然后每次取数只能取3的倍数。

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
#include<iostream>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int n,t=0;
cin>>n;
while(n--){
string s;
cin>>s;
int cnt=0,sum=0,b=0,c=0;
for(int i=0;i<s.size();i++){
sum+=s[i]-'0';
if(s[i]%3==1) b++;
else if(s[i]%3==2) c++;
else cnt++;
}
cout<<"Case "<<++t<<": ";
if(sum%3==1) if(b) cnt++;
if(sum%3==2) if(c) cnt++;
if(cnt%2) cout<<"S";
else cout<<"T";
cout<<endl;
}
return 0;
}

** 本文迁移自我的CSDN博客,格式可能有所偏差。 **