0%

[題解]99遊戲

a113. 99遊戲

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;

map<int,queue<string>> mp;

int main(){
for(int i=0;i<4;i++){
char ch;cin>>ch;
for(int j=0;j<13;j++){
string s;cin>>s;
mp[ch-'A'].push(s);
}
}
int id = 0,dir=1,sum=0;
while(sum<=99){
string card = mp[id].front();
if(card=="A")sum=0;
else if(card=="4")dir*=-1;
else if(card=="5");
else if(card=="10"){
sum+=10;
if(sum>99)sum-=20;
}
else if(card=="J");
else if(card=="Q"){
sum+=20;
if(sum>99)sum-=40;
}
else if(card=="K")sum=99;
else{
sum+=(card[0]-'0');
if(sum>99){
cout<<char('A'+id)<<endl<<mp[id].size()-1<<endl;
break;
}
}
mp[id].pop();
if(mp[id].empty()){
cout<<char('A'+id)<<endl<<sum<<endl;
break;
}
id = (id+dir+4)%4;
// cout<<sum<<endl;
}
}