fork download
  1. #include <iostream>
  2. #include<stdio.h>
  3. #include<memory.h>
  4. #include<limits.h>
  5. #include<string.h>
  6. using namespace std;
  7.  
  8. char str[100005];
  9. int hashmap[300];
  10. int main()
  11. {
  12. int t,n,i,j,maxlen,prev_index,cur_len;
  13. scanf("%d",&t);
  14. while(t--)
  15. {
  16. memset(hashmap,-1,sizeof(hashmap));
  17. scanf("%s",str);
  18. maxlen=1;
  19. cur_len=1;
  20. hashmap[str[0]]=0;
  21. n=strlen(str);
  22. for(i=1;i<n;i++)
  23. {
  24. prev_index=hashmap[str[i]];
  25.  
  26. if(prev_index==-1||i-cur_len>prev_index)
  27. {
  28. cur_len++;
  29. }
  30. else
  31. {
  32. if(maxlen<cur_len)
  33. maxlen=cur_len;
  34.  
  35. cur_len=i-prev_index;
  36. }
  37. hashmap[str[i]]=i;
  38. }
  39. if(cur_len>maxlen)
  40. maxlen=cur_len;
  41.  
  42. printf("%d\n",maxlen);
  43. }
  44. // your code goes here
  45. return 0;
  46. }
Success #stdin #stdout #stderr 0.03s 6952KB
stdin
10
aba
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
stdout
Standard output is empty
stderr
ERROR: /home/mEwMBN/prog:46:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? % Execution Aborted
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit