fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int lps(string);
  4. int main()
  5. {
  6. //code
  7. int T;
  8. cin >> T;
  9. getchar();
  10. while (T–) {
  11. string s;
  12. cin >> s;
  13. printf("% d\n", lps(s));
  14. }
  15. return 0;
  16. }
  17. int lps(string s)
  18. {
  19. int n = s.size();
  20. int lps[n];
  21. int i = 1, j = 0;
  22. lps[0] = 0;
  23. while (i < n) {
  24. if (s[i] == s[j]) {
  25. j++;
  26. lps[i] = j;
  27. i++;
  28. }
  29. else {
  30. if (j != 0)
  31. j = lps[j – 1];
  32. else {
  33. lps[i] = 0;
  34. i++;
  35. }
  36. }
  37. }
  38. return lps[n – 1];
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1
abcabca
compilation info
prog.cpp:10:13: error: non-ASCII characters are not allowed outside of literals and identifiers
    while (T–) {
            ^
prog.cpp:31:27: error: non-ASCII characters are not allowed outside of literals and identifiers
                j = lps[j – 1];
                          ^~
prog.cpp:31:31: error: expected ']'
                j = lps[j – 1];
                            ^
prog.cpp:31:24: note: to match this '['
                j = lps[j – 1];
                       ^
prog.cpp:38:18: error: non-ASCII characters are not allowed outside of literals and identifiers
    return lps[n – 1];
                 ^~
prog.cpp:38:22: error: expected ']'
    return lps[n – 1];
                   ^
prog.cpp:38:15: note: to match this '['
    return lps[n – 1];
              ^
5 errors generated.
stdout
Standard output is empty