fork download
  1. string lastSubstring(string s) {
  2. char c='a';
  3. int id=0;
  4. string res=" ";
  5. string str;
  6. int j,k,i;
  7. vector<int> idx;
  8. for(i=0;i<s.length();i++)
  9. {
  10. if(s[i]>c)
  11. {
  12. c=s[i];
  13. }
  14. }
  15. for(i=0;i<s.length();i++)
  16. {
  17. if(s[i]==c)
  18. {
  19. idx.push_back(i);
  20. }
  21. }
  22. int n=s.length();
  23. if(idx.size()==1)
  24. {
  25. res=s.substr(idx[0],s.length()-idx[0]);
  26. return res;
  27. }
  28.  
  29. i=idx[0],j=idx[1],k=0,id=1;
  30.  
  31. while((i+k)<n&&(j+k)<n)
  32. {
  33. if(s[i+k]==s[j+k])
  34. {
  35. k++;
  36. }
  37. else if(s[i+k]<s[j+k])
  38. {
  39. i=j;
  40. j=i+1;
  41. k=0;
  42. }
  43. else if(s[i+k]>s[j+k])
  44. {
  45. j=j+k+1;
  46. k=0;
  47. }
  48. }
  49. res=s.substr(i,s.length()-i);
  50. return res;
  51. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘string’ does not name a type; did you mean ‘struct’?
 string lastSubstring(string s) {
 ^~~~~~
 struct
stdout
Standard output is empty