Problem Description
输入一篇英文文本,统计行数、单词数、字符数。
Input Description
输入一篇英文文本。
Output Description
式“nl=行数,nc=字符数,nw=单词数”输出统计结果。
Sample Input
按照格
You Have Only One Life!
Sample Output
nl=1,nc=24,nw=5
代码:
#include <stdio.h>
#define IN 1
#define OUT 0
int main(void)
{
int nl, nc, nw, x = OUT;
char ch;
nw = 0;
nl = 0;
nc = 0;
while((ch = getchar()) != EOF)
{
if(ch == '\n')
nl++;
if(ch == ' ' || ch == '\n' || ch == '\t')
x = OUT;
else if(x == OUT)
{
nw++;
x = IN;
}
nc++;
}
printf("nl=%d,nc=%d,nw=%d", nl, nc, nw);
return 0;
}
注意:
先按enter
再按Ctrl + c、
就可以显示结果