问题 J: 例题6-9 字符串求最大值

问题 J: 例题6-9 字符串求最大值

时间限制: 1 Sec  内存限制: 12 MB
献花: 166  解决: 143
[献花][花圈][TK题库]

题目描述

从键盘上输入3个字符串,求出其中最大者。

输入

输入3行,每行均为一个字符串。

输出

一行,输入三个字符串中最大者。

样例输入

England
China
America

样例输出

England

参考代码:

#include<stdio.h>
#include<string.h>        //为了使用strcmp()函数,该函数直接比较两个字符串的大小
int main(){
  char a[100],b[100],c[100];
  gets(a);           //输入字符串,并保存到数组a,b,c中
  gets(b);
  gets(c);
  int ptr1=strcmp(a,b);
  if(ptr1>0){         //若ptr1>0,则表示数组a大于数组b
    int ptr2=strcmp(a,c);
    if(ptr2>0){
      printf("%s",a);   //输出字符串型数组
    }else{
      printf("%s",c);
    }
  }else{
    int ptr2=strcmp(b,c);
    if(ptr2>0){
      printf("%s",b);
    }else{
      printf("%s",c);
    }
  }


return 0;
}

 
posted @ 2017-10-29 22:10  csuzhhj  阅读(503)  评论(0编辑  收藏  举报