7-2 找出最长的单词-hebust

7-2 找出最长的单词-hebust

找出长度最长的单词(不同长度的单词只出现一次)。

输入格式:

输入格式为单行形式,单词之间使用空格分割。

输出格式:

输出格式为长度最长的一个单词。

输入样例:

在这里给出一组输入。例如:

an not need happy suggest

输出样例:

在这里给出相应的输出。例如:

suggest

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int maxwords;
    string words,words2;

    cin>>words;

    while(cin>>words2){

        if(words.size()<words2.size()){
            words = words2;
        }
        char turn = getchar();
        if(turn=='\n'){
            break;
        }
    }
    cout<<words;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37871668/article/details/88947298
7-2