fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int t;
  5. cin>>t;
  6. while(t--)
  7. {
  8. int pc=-1,cc=-1,a=0,b=0,lad=0,i,cno=0;
  9. string str;
  10. cin>>str;
  11. int len=str.length();
  12. for(i=0;i<len;i++)
  13. {
  14. if(str[i]!='.')
  15. {
  16. cno++;
  17. cc=i;
  18. break;
  19. }
  20. if(i==len-1)
  21. cout<<'B'<<endl;
  22. }
  23. if(i==len)
  24. continue;
  25. for(i=cc+1;i<len;i++)
  26. {
  27. if(str[i]!='.')
  28. {
  29. pc=cc;
  30. cc=i;
  31. cno++;
  32. if(cno%2==0)
  33. {
  34. if((str[pc]==str[cc])&&str[cc]=='A')
  35. a+=cc-pc-1;
  36. if((str[pc]==str[cc])&&str[cc]=='B')
  37. b+=cc-pc-1;
  38. if(str[pc]=='A'&&str[cc]=='B'&&cc!=pc+1)
  39. lad++;
  40. if(str[pc]=='B'&&str[cc]=='A'&&cc!=pc+1)
  41. lad++;
  42.  
  43. }
  44. }
  45. }
  46. if(cno%2==1)
  47. {
  48. if(str[cc]=='A')
  49. a+=len-cc-1;
  50. else
  51. b+=len-cc-1;
  52. }
  53. if(lad!=0)
  54. {
  55. lad=lad%2;
  56. if(lad==0)
  57. b++;
  58. else
  59. a++;
  60. }
  61. //cout<<a<<" "<<b<<endl;
  62. if(a>b)
  63. cout<<'A'<<endl;
  64. else
  65. cout<<'B'<<endl;
  66. }
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0s 15240KB
stdin
3
A.B
A..B
A..B.A..B
stdout
A
A
B