codeup之字符串求最大值
Description
从键盘上输入3个字符串,求出其中最大者。
Input
输入3行,每行均为一个字符串。
Output
一行,输入三个字符串中最大者。
Sample Input Copy
England
China
America
Sample Output Copy
England
solution
#include <stdio.h>
#include <string.h>
int main(){
char str[3][10];
for(int i = 0; i < 3; i++)
gets(str[i]);
if(strcmp(str[0],str[1]) > 0){
if(strcmp(str[0],str[2]) > 0)
puts(str[0]);
else
puts(str[2]) ;
}
else{
if(strcmp(str[1],str[2]) > 0)
puts(str[1]);
else
puts(str[2]) ;
}
return 0;
}