您的位置:首页 > 其它

华中科技,最短最长文本

2016-03-07 10:44 369 查看
要注意只有一个字符串的时候,不能重复输出,并且当有字符串都相等时,也不能重复输出

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;

int main(){
string str[1000];
//int len[1000];//每个字符串的长度;
int min = -1;
int max = 0;
int count = 0;//字符串数
int flag[1000];
while(cin>>str[count]){
//len[count] = str[count].length();
if(max<str[count].length())
max = str[count].length();
if(min>str[count].length())
min = str[count].length();
count++;
}
for(int i = 0;i<count;i++){
if(str[i].length()==min){
cout<<str[i]<<endl;
flag[i] = 1;
}
}
for(int i = 0;i<count;i++){
if(str[i].length()==max){
if(!flag[i])
cout<<str[i]<<endl;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: