fork(1) download
  1. #include <bits/stdc++.h>
  2. #include <string>
  3. using namespace std;
  4.  
  5. string LongestWord(string sen) {
  6.  
  7. // code goes here
  8. string s=sen;
  9. int count=0;
  10. int max1=0;
  11. int j=0;
  12. int k=0;
  13. for(int i=0;i<s.size();i++){
  14. if(s[i]==' '){
  15. if(count>max1){
  16. max1=count;
  17. j=k;
  18. k=i;
  19. cout<<i<<" "<<endl;
  20. cout<<count<<endl;
  21. }
  22. count=0;
  23. continue;
  24. }
  25. else if(isalpha(s[i])){
  26. //cout<<s[i];
  27. count=count+1;
  28. }
  29. else{
  30. continue;
  31. }
  32. }
  33.  
  34. if(count>max1){
  35. max1=count;
  36. s=s.substr(k,sen.size()-1);
  37. }
  38. else{
  39. s=s.substr(j,k);
  40. }
  41. return s;
  42.  
  43. }
  44.  
  45. int main(void) {
  46.  
  47. // keep this function call here
  48. string s;
  49. cin>>s;
  50. cout << LongestWord(s);
  51. return 0;
  52.  
  53. }
Success #stdin #stdout 0s 5340KB
stdin
this is some sort of sentence
stdout
thi