D题解
这题对题目给出的所有条件进行特判即可
直接贴代码
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
int l = s.length();
string cnt1="0", cnt2="0";
int flag1 = -1, flag2 = -1;
for(int i=0; i<l; ++i){
if(s[i]=='A'){
if(cnt1 == "0") cnt1 = "15";
else if(cnt1 == "15") cnt1 = "30";
else if(cnt1 == "30") cnt1 = "40";
else if(cnt1 == "40" && cnt2!="40" && cnt2!="AD"){
flag1 = i;
break;
}
else if(cnt1 == "40" && cnt2=="40") cnt1 = "AD";
else if(cnt1 == "40" && cnt2=="AD") cnt2 = "40";
else if(cnt1 == "AD"){
flag1 = i;
break;
}
}else{
if(cnt2 == "0") cnt2 = "15";
else if(cnt2 == "15") cnt2 = "30";
else if(cnt2 == "30") cnt2 = "40";
else if(cnt2 == "40" && cnt1!="40" && cnt1!="AD"){
flag2 = i;
break;
}
else if(cnt2 == "40" && cnt1=="40") cnt2 = "AD";
else if(cnt2 == "40" && cnt1=="AD") cnt1 = "40";
else if(cnt2 == "AD"){
flag2 = i;
break;
}
}
}
if(flag1 == l-1) cout<<"A won"<<endl;
else if(flag2 == l-1) cout<<"B won"<<endl;
else if(flag1 != -1 || flag2!=-1) cout<<"INVALID"<<endl;
else cout<<cnt1<<":"<<cnt2<<endl;
return 0;
}