oepnJudge | 最长单词2 C语言-答案

时间:2024-02-16 22:21:16
#include <stdio.h>
#include <string.h>
typedef struct {
    char word[600];
    int len;
} word;
int main() {
    static word word_, wordMax;
    static char str[600], *p = str, *q;
    gets(str);
    for(; *p != 0; p++) {
        if(*p != ' ' && *p != '.') {
            word_.word[word_.len++] = *p;
        } else {
            if(wordMax.len < word_.len) {
                wordMax.len = word_.len;
                strcpy(wordMax.word, word_.word);
            }
            for(q = word_.word; *q != 0; q++) {
                *q = 0;
            }
            word_.len = 0;
        }
    }
    puts(wordMax.word);
}