搜索
您的当前位置:首页正文

ALGO-70算法训练 最长字符串  (c++)

来源:好走旅游网

算法训练 最长字符串  

时间限制:1.0s   内存限制:512.0MB

    

  求出5个字符串中最长的字符串。每个字符串长度在100以内,且全为小写字母。

样例输入

one two three four five

样例输出

three

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

int main(int argc, char *argv[]) {
	string s[5];
	int m=0,p=0;
	for(int i=0;i<5;i++){
		cin>>s[i];
		if(s[i].length()>m){
			m=s[i].length();
			p=i;
		}
	}
	cout<<s[p]<<endl;		
	return 0;
}

 

因篇幅问题不能全部显示,请点此查看更多更全内容

Top