fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <string>
  5. using namespace std;
  6. int main() {
  7. int len1[500] = { 0 };
  8. char str1[500]{};//zero init
  9. char str2[500]{};//zero init
  10. char str3[500]{};//zero init
  11. int i = 0;
  12. int j = 0;
  13. int len = 0;
  14. int string_counter = 0;
  15. int len_counter = 0;
  16. int temp = 0;
  17. int max_index = 0;
  18. int x = 0;
  19. string str_arr[10] = {};
  20. cin.getline(str1, 500);
  21. while (str1[j] != '\0') {
  22. if (str1[j] != ' ' && str1[j] != '.') {// skip '.' and ' '
  23.  
  24. str2[len_counter] = str1[j]; //copy str1 each word to str2
  25. len_counter++;
  26. j++;
  27. }
  28. else {
  29. len1[len] = len_counter; //record each word lenth
  30. str_arr[string_counter] = str2;
  31.  
  32. memset(str2, 0, sizeof(str2)); // clear temporary str2
  33. len_counter = 0;
  34. string_counter++;
  35. len++;
  36. j++;
  37. }
  38.  
  39. }
  40. for (int a = 0; a < 10; a++) {
  41. //cout << len1[a];
  42. }
  43. while (len1[x] != 0) {
  44. if (len1[x]> temp) {
  45. temp = len1[x];
  46. max_index = x;
  47.  
  48. }
  49. x++;
  50.  
  51. }
  52. //don't need it
  53. //str_arr[max_index] += '\0';
  54. cout << str_arr[max_index];
  55.  
  56.  
  57.  
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 4476KB
stdin
Standard input is empty
stdout
Standard output is empty