九度题目1182:统计单词

来源:互联网 发布:linux w3m 使用 编辑:程序博客网 时间:2024/05/29 03:56

http://ac.jobdu.com/problem.php?pid=1182

2002年华中科技大学计算机研究生机试真题

将输入一行字符串转为单个输入单词,每次输出个数,若最后一个字符是.则结束本行输入

熟悉双重while循环的输入方式

#include <stdio.h>#include <string.h>char str[1000];int main(){freopen("D:\\1.txt","r",stdin);int i;   while (scanf("%s",str)!=EOF)   {   int len=strlen(str);       if (str[len-1]=='.')       {   printf("%d\n",len-1);   continue;       }   else   printf("%d ",len);   while (1)   {   scanf("%s",str);   len=strlen(str);   if (str[len-1]=='.')   {   printf("%d\n",len-1);   break;   }   else       printf("%d ",len);   }        }}


原创粉丝点击