fork download
  1. #include<bits/stdc++.h>
  2. //Phan thanh Nhàn
  3. using namespace std;
  4. void c2a(char* s){
  5. char tmp[100];
  6. strcpy(tmp,s);
  7. char* token=strtok(tmp," ");
  8. while(token){
  9. cout<<strlen(token)<<" ";
  10. token=strtok(NULL," ");
  11. }
  12. }
  13.  
  14. void c2b(char* s){
  15. char tmp[100],ans[100];
  16. strcpy(tmp,s);
  17. char* token=strtok(tmp," ");
  18. int max=strlen(token);
  19. while(token){
  20. if(strlen(token)>max){
  21. max=strlen(token);
  22. strcpy(ans,token);
  23. }
  24. token=strtok(NULL," ");
  25. }
  26. cout<<ans;
  27. }
  28.  
  29.  
  30. int main(){
  31. char s[]={"ChatGPT provides excellent support for research as well as many other tasks"};
  32. c2b(s);
  33.  
  34. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
excellent