Midterm 2

pA

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
#include<iostream>
#include<vector>
#include<map>
#include<set>

#define debug(x) cout<<#x<<": "<<x<<',';
#define el cout<<endl;
#define pb(x) push_back(x)

using namespace std;

map<char,int> m={{'A',10},{'B',11},{'C',12},{'D',13},{'E',14},{'F',15},{'G',16},{'H',17},{'J',18},{'K',19},{'L',20},{'M',21},{'N',22},{'P',23},{'Q',24},{'R',25},{'S',26},{'T',27},{'U',28},{'V',29},{'X',30},{'Y',31},{'W',32},{'Z',33},{'I',34},{'O',35}};
int times[]={1,9,8,7,6,5,4,3,2,1,1};

signed main(){
string s,tmp="";int ans=0;
cin>>s;
tmp+=to_string(m[s[0]]);
for(int i=1;i<s.length();i++){
tmp+=s[i];
}
s=tmp;
for(int i=0;i<s.length();i++){
ans+=(int(s[i])-48)*times[i] ;
}
int l;
while(cin>>l&&l!=0){
if(l==1){
cout<<s<<endl;
}
if(l==2){
cout<<ans<<endl;
}
if(l==3){
if(ans%10)cout<<0<<endl;
else cout<<1<<endl;
}
}
return 0;
}

pB

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<iostream>
#include<vector>
#include<map>
#include<set>

#define debug(x) cout<<#x<<": "<<x<<',';
#define el cout<<endl;
#define pb(x) push_back(x)

using namespace std;

map<char,vector<string>> cards;
char hh[]={'N','E','S','W'};
char aa[]={'S','W','N','E'};
map<char,int> mnp={{'N',0},{'E',1},{'S',2},{'W',3}};
char fb[]={'C','D','S','H'};
char sb[]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
vector<string> test={"H2","SQ","D9","C5"};

vector<string> srt(vector<string> us){
vector<string> s1,s2;
for(auto i:sb){
for(auto j:us){
if(j[1]==i){
s1.pb(j);
}
}
}
for(auto i:fb){
for(auto j:s1){
if(j[0]==i){
s2.pb(j);
}
}
}
return s2;
}


signed main(){
char c;vector<string> kd;int n;string tmp;
cin>>c;
for(int i=0;i<52;i++){
cin>>tmp;
kd.pb(tmp);
}
cout<<"Enter Number :";
cin>>n;
int np=mnp[c]+1;
while(!kd.empty()){
if(np>3)np=0;
cards[hh[np]].pb(kd[0]);
kd.erase(kd.begin());
np++;
}
if(n==1){
for(auto i:hh){
for(auto j:cards[i]){
if(j=="C3"){
cout<<i<<endl;
return 0;
}
}
}
}
if(n==2){
for(auto i:aa){
cout<<i<<':';
for(auto j:cards[i]){
cout<<' '<<j;
}
cout<<endl;
}
}
if(n==3){
for(auto i:aa){
cout<<i<<':';
for(auto j:srt(cards[i])){
cout<<' '<<j;
}
cout<<endl;
}
}
return 0;
}