题目:
http://blog.csdn.net/qq_35786326/article/details/79211470
题意:
求每一局游戏的胜者是谁?而如果是MaoLaoDa胜,那么还有输出ta第一次至少要拿多少块金块
分析:
当看到题目的第一眼时,小编差点没从坐位上掉下来,毕竟是10^1000002的范围。但经过思考后,才发现这题有规律可循:当我们将输入的金块数,每个数位进行累加,得x。而如果x是3的倍数,那么就是King will win而MaoLaoDa will win则反之,而ta至少要拿的块数,则是x%3的结果
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
inline LL read() {
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
int main()
{
freopen("atlantis.in","r",stdin);
freopen("atlantis.out","w",stdout);
int c;
for(int i=1;i<=3;i++)
{
string s;
cin>>s;
c=0;
for(int i=0;i<s.size();i++) c+=s[i]-48;//规律如上述,不多解释
if(c%3==0) printf("King will win.\n");
else printf("MaoLaoDa will win.\n%d\n",c%3);
}
fclose(stdin);
fclose(stdout);
return 0;
}