fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. map<string, bool> used;
  6. string S = "a";
  7. int k;
  8. cin >> k;
  9. for(int j = 1; ; j += 1){
  10. for(int i = 0; i < k; i += 1){
  11. string current = "aa";
  12. current[0] = S.back();
  13. current[1] = char('a' + i);
  14. if(!used[current]){
  15. S += char('a' + i);
  16. used[current] = true;
  17. break;
  18. }
  19. }
  20. if(S.size() != j+1) break;
  21. }
  22. cout << S;
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5516KB
stdin
6
stdout
aabacadaeafa