-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpalingam.cpp
81 lines (69 loc) · 1.66 KB
/
palingam.cpp
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
#include<bits/stdc++.h>
#define MAX 1000001
#define ll long long
#define DEBUG(x) do { std::cout << #x << ": " << x << " "; } while (0)
using namespace std;
int main()
{
int z,n,i,j,x,y,ans,flag;
cin>>z;
char s[1000],t[1000],w[2000];
int a[26],b[26],c[26];
while(z--){
cin>>s>>t;
ans=flag=1;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=0;s[i]!='\0';++i){
a[s[i]-'a']++;
}
for(i=0;t[i]!='\0';++i){
b[t[i]-'a']++;
}
x=0;
for(i=0;i<26;++i){
if(a[i]>=2 && b[i]==0){
ans=0;
//cout<<" "<<a[i];
flag=0;
break;
}
}
if(flag)
{
for(j=0;s[j]!='\0';++j){
x=y=0;
for(i=0;i<26;++i){
if(a[i]>0 && b[i]==0){
x+=1;
a[i]--;
break;
}
}
for(i=0;i<26;++i){
if(b[i]>0 && a[i]==0){
y+=1;
b[i]--;
break;
}
}
if(x==0){
ans=1;
//cout<<" 2 ";
break;
}
else if(y==0){
ans=0;
break;
}
}
}
if(ans==1){
cout<<"B\n";
}
else{
cout<<"A\n";
}
}
return 0;
}