Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created January 25, 2014 12:58
Show Gist options
  • Save KT-Yeh/8615998 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8615998 to your computer and use it in GitHub Desktop.
#include <cstdio>
using namespace std;
int main()
{
int T,Case=1;
scanf("%d",&T);
getchar();
while (T--){
int N[1001],nOfN=0; //用來存非3的倍數的數字
int nOf3x = 0; //該位數為3的倍數的個數
int sum = 0; //非3倍數的和
while (1){
char c = getchar();
if (c == '\n') break;
else if ((c-'0')%3 == 0) nOf3x++;
else {
N[nOfN++] = (c-'0');
sum += (c-'0');
}
}
int who; //who為偶數代表S,奇數代表T
if (nOf3x % 2) who = 0;
else who = 1;
if (sum%3 !=0) {
int i;
for (i=0; i<nOfN; i++)
if ((sum-N[i])%3 == 0) break;
if (i==nOfN) who=1;
else who++;
}
printf("Case %d: ",Case++);
if (who % 2) printf("T\n");
else printf("S\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment