Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- char c = ' ', prev = ' '; // previous
- char w_max[2000]; // max word
- char w_temp[2000]; // temp word
- for (int i = 0; i < 2000; ++i) {
- /* '\0' => end of line */
- w_max[i] = '\0';
- w_temp[i] = '\0';
- }
- int max_len = 0; // max word's length
- int t_len = 0; // temp word's length
- int index = 0;
- while (c != '\n') {
- prev = c;
- scanf("%c", &c);
- if (c >= 'a' && c <= 'z') { // ['a';'z']
- t_len += 1;
- w_temp[index] = c; index++; // 'a' -> 0, 'b' -> 1
- } else if (prev >= 'a' && c <= 'z') {
- if (max_len < t_len) {
- max_len = t_len;
- for (int i = 0; i < max_len; ++i) w_max[i] = w_temp[i];
- }
- for (int i = 0; i < t_len; ++i) {
- printf("%c", w_temp[i]);
- }
- printf("\n"); // new line
- index = 0;
- t_len = 0;
- for (int i = 0; i < 2000; ++i) {
- w_temp[i] = '\0';
- }
- }
- }
- printf("\n");
- for (int i = 0; i < max_len; ++i) {
- printf("%c", w_max[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement