1058. 统计单词
题目描述
输入一段由若干个以空格分隔的单词组成的英文文章,求出文章中最短的单词(文章以英文句点“.”结束,且字符总数不超过200)。
输入
输入文章。
输出
输出最早的最短的单词。
样例输入
We are Oiers.
样例输出
We
数据范围限制
C++代码
#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
const int max_len = 200;
char strText[max_len+1], ans[max_len+1];
int min_len = max_len;
int len;
while(1)
{
cin >> strText;
len = strlen(strText);
if(strText[len-1] == '.')
{
strText[--len] = '\0';
if(len < min_len)
{
strcpy(ans, strText);
}
break; // end mark is found, so jump out of loop
}
else
{
if(len < min_len)
{
min_len = len;
strcpy(ans, strText);
}
}
}
cout << ans << endl;
return 0;
}