fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. //code
  6. int t,n;
  7. cin>>t;
  8. while(t--)
  9. {
  10.  
  11. char str[10000];
  12. cin.getline(str,10000);
  13. int len=0,max=0,i=0;
  14. bool hash[256]={0};
  15. int prev[256]={0},temp;
  16. while(str[i])
  17. {
  18. if(hash[str[i]]==0)
  19. {
  20. hash[str[i]]=1;
  21. len++;
  22. prev[str[i]]=i;
  23. if(len>max)
  24. max=len;
  25. }
  26. else
  27. {
  28. len=0;
  29. for(int j=0;j<256;j++)
  30. hash[j]=0;
  31. temp=i;
  32. i=prev[str[i]];
  33. prev[str[i]]=temp;
  34. }
  35. i++;
  36. }
  37. cout<<len<<endl;
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 3460KB
stdin
2
abababcdefababcdab
geeksforgeeks
stdout
0
4