1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-27 08:26:20 +00:00
202401-programming-assignments/【实践课外】6.循环结构3/7-4 单词长度.c

40 lines
688 B
C
Raw Permalink Normal View History

2024-11-02 12:58:43 +00:00
#include <stdio.h>
int main() {
char c;
int count = 0;
int printed = 0;
while (scanf("%c", &c) != EOF, c != '.') {
if (c == ' ') {
if (count != 0) {
if (printed == 0) {
printf("%d", count);
printed = 1;
} else {
printf(" %d", count);
}
}
count = 0;
} else {
count++;
}
}
if (count != 0) {
if (printed == 0) {
printf("%d", count);
printed = 1;
} else {
printf(" %d", count);
}
}
printf("\n");
return 0;
}