Largest string

Largest string

Enter 3 character strings, find and output the largest character string among them.

The input has three lines, each line contains a string without spaces, and the length of each string does not exceed 100.

The largest one of the three character strings read in is output in one line.
Please pay attention to the line ending output.

enter

CHINA
HOLLAND
AMERICA

Output

HOLLAND
// 最大的字符串
#include<iostream>
#define N 100		//字符串长度上限
using namespace std;
int main(void)
{
    
    
    char line[3][N]={
    
    '\0'};
    for (int i=0;i<3;i++)
        cin>>line[i];
     //两两比较
    for (int i=0;i<N;i++)
    {
    
    
        if (line[0][i]>line[1][i])
        {
    
    
            if (line[1][i]>line[2][i])
            {
    
    cout<<line[0];
            return 0;
            }   
            else
            {
    
       if (line[0][i]>line[2][i])
                {
    
       cout<<line[0];
                return 0;
                }
                else {
    
    cout<<line[2];
                return 0;
                }
            }
        }
        if (line[0][i]<line[1][i])
        {
    
    
            if (line[1][i]<line[2][i])
                {
    
    cout<<line[2];
                return 0;
                }
            else
            {
    
       cout<<line[1];
            return 0;
            }
        }
         
    }
} 

Guess you like

Origin blog.csdn.net/qq_45830912/article/details/114101511