fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <utility>
  7. #include <map>
  8. #include <set>
  9. #include <string>
  10. #include <cstring>
  11. #include <queue>
  12. #define rf freopen("in.in", "r", stdin)
  13. #define wf freopen("out.out", "w", stdout)
  14. #define rep(i, s, n) for(int i=int(s); i<=int(n); ++i)
  15. using namespace std;
  16. const int mx = 1e5 + 10, mod = 1e9+7;
  17.  
  18. int main()
  19. {
  20. //rf;// wf;
  21. ios::sync_with_stdio(0);
  22.  
  23. int t; cin >> t;
  24. while(t--)
  25. {
  26. string s;
  27. cin >> s;
  28. int n = s.size();
  29.  
  30. int cnt_a = 0, cnt_b = 0;
  31. rep(i, 0, n-1)
  32. {
  33. cnt_a += (s[i] == 'A');
  34. cnt_b += (s[i] == 'B');
  35. }
  36.  
  37. if(cnt_a == 2)
  38. {
  39. cout << "A\n";
  40. continue;
  41. }
  42. else if(cnt_b == 2)
  43. {
  44. cout << "B\n";
  45. continue;
  46. }
  47. else if(n < 4)
  48. {
  49. cout << "-1\n";
  50. continue;
  51. }
  52.  
  53. string ans = "";
  54. s = '.' + s + '.';
  55. for(int i = 0; i <= n-2; ++i)
  56. {
  57. if(s[i+2] != s[i+3] and s[i+1] == s[i+2] and s[i] != s[i+1])
  58. {
  59. rep(j, 1, n)
  60. {
  61. if(j!=i+1)
  62. ans += s[j];
  63. }
  64. break;
  65. }
  66. }
  67.  
  68. cout << ((ans == "")? "-1": ans) << endl;
  69. }
  70.  
  71. return 0;
  72. }
Success #stdin #stdout 0s 3460KB
stdin
1
ABABABABABABABBABABABABABABABABABAB
stdout
ABABABABABABABABABABABABABABABABAB