Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.    char c = ' ', prev = ' '; // previous
  5.    char w_max[2000]; // max word
  6.    char w_temp[2000]; // temp word
  7.  
  8.    for (int i = 0; i < 2000; ++i) {
  9.       /* '\0' => end of line */
  10.       w_max[i] = '\0';
  11.       w_temp[i] = '\0';
  12.    }
  13.  
  14.    int max_len = 0; // max word's length
  15.    int t_len = 0; // temp word's length
  16.    int index = 0;
  17.    while (c != '\n') {
  18.       prev = c;
  19.       scanf("%c", &c);
  20.       if (c >= 'a' && c <= 'z') { // ['a';'z']
  21.          t_len += 1;
  22.          w_temp[index] = c; index++; // 'a' -> 0, 'b' -> 1
  23.       } else if (prev >= 'a' && c <= 'z') {
  24.          if (max_len < t_len) {
  25.             max_len = t_len;
  26.             for (int i = 0; i < max_len; ++i) w_max[i] = w_temp[i];
  27.          }
  28.          for (int i = 0; i < t_len; ++i) {
  29.             printf("%c", w_temp[i]);
  30.          }
  31.          printf("\n"); // new line
  32.          index = 0;
  33.          t_len = 0;
  34.          for (int i = 0; i < 2000; ++i) {
  35.             w_temp[i] = '\0';
  36.          }
  37.       }
  38.    }
  39.  
  40.    printf("\n");
  41.    for (int i = 0; i < max_len; ++i) {
  42.       printf("%c", w_max[i]);
  43.    }
  44.  
  45.    return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement