-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathPALINGAM.cpp
More file actions
92 lines (90 loc) · 1.53 KB
/
PALINGAM.cpp
File metadata and controls
92 lines (90 loc) · 1.53 KB
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
86
87
88
89
90
91
92
//Code Copyright: Sanskar Jain, Software Engineering 2nd Year, DTU
#include <iostream>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
map<char,int> c,d;
map<char,int>::iterator it;
string a,b;
int e[26],f[26],g[501],h[501];
memset(e,0,sizeof(e));
memset(f,0,sizeof(f));
memset(g,0,sizeof(g));
memset(h,0,sizeof(h));
cin>>a>>b;
if(a==b){
cout<<"B\n";
continue;
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(a==b){
cout<<"B\n";
continue;
}
for(int i=0;i<a.length();i++){
e[a[i]-97]++;
if(c.find(a[i])!=c.end()){
c[a[i]]++;
}
else{
c.insert(pair<char,int>(a[i],1));
}
}
for(int i=0;i<b.length();i++){
f[b[i]-97]++;
if(d.find(b[i])!=d.end()){
d[b[i]]++;
}
else{
d.insert(pair<char,int>(b[i],1));
}
}
for(int i=0;i<26;i++){
g[e[i]]++;
h[f[i]]++;
}
char winner='B';
int flag=0;
for (it=c.begin(); it!=c.end(); ++it){
if(it->second>=2&&d.find(it->first)==d.end()){
winner='A';
goto result;
}
}
for (it=c.begin(); it!=c.end(); ++it){
if(d.find(it->first)==d.end()){
flag=1;
}
}
if(flag==0){
winner='B';
goto result;
}
for(int i=0;i<26;i++){
if(f[i]==1&&e[i]==0){
winner='B';
goto result;
}
}
flag=0;
if(g[1]!=0){
for (it=d.begin(); it!=d.end(); ++it){
if(c.find(it->first)==c.end()){
flag=1;
}
}
if(flag==0){
winner='A';
goto result;
}
}
result:
cout<<winner<<"\n";}
return 0;
}