fork download
  1. // Online C++ compiler to run C++ program online
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. bool postojiDupli(vector<char>& arr) {
  7.  
  8.  
  9. unordered_set<char> s;
  10. for (char x : arr) {
  11. if (s.find(x) != s.end())
  12. return true;
  13. s.insert(x);
  14. }
  15. return false;
  16. }
  17.  
  18. int main() {
  19. int t;
  20. cin >> t;
  21. while(t--){
  22. int n;
  23. string s;
  24. cin >> n >> s;
  25. vector<char> niz(n-2);
  26. for (int i = 0; i < n-2; i++){
  27. niz.push_back(s[i+1]);
  28. }
  29. for (int i = 0; i < n-2; i++){
  30. cout << niz[i] << " ";
  31. }
  32.  
  33. if (postojiDupli(niz)){
  34. cout << "YES" << '\n';
  35. }
  36. else cout << "NO" << '\n';
  37.  
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 5320KB
stdin
12
3
aaa
3
aba
3
aab
4
abca
4
abba
4
aabb
5
abaca
5
abcda
5
abcba
6
abcbbf
6
abcdaa
3
abb
stdout
 NO
 NO
 NO
  YES
  YES
  YES
   YES
   YES
   YES
    YES
    YES
 NO