海洋之心


私信TA

用户名:wanggongsheng

访问量:122720

签 名:

等  级
排  名 17
经  验 20536
参赛次数 3
文章发表 163
年  龄 26
在职情况 学生
学  校
专  业 计算机技术

  自我简介:

读研ing,平时不登录dotcpp

#include<string.h>
#include<stdio.h>
int main(void)
{
	char s1[100];
	char s2[100];
	char s3[100];
	char temp[100];
	scanf("%s%s%s",s1,s2,s3);
	if(strcmp(s1,s2)>0) strcpy(temp,s1),strcpy(s1,s2),strcpy(s2,temp);
	if(strcmp(s1,s3)>0) strcpy(temp,s1),strcpy(s1,s3),strcpy(s3,temp);
	if(strcmp(s2,s3)>0) strcpy(temp,s2),strcpy(s2,s3),strcpy(s3,temp);	
	printf("%s\n%s\n%s",s1,s2,s3);
	return 0;
}


 

0.0分

3 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

为什么if语句必须设置为 (strcmp(s1,s2)>0)  ,为什么不可以 (strcmp(s1,s2)==1)  ?
2018-05-28 23:20:37
#include<string.h>
#include<stdio.h>
int main(void)
{
    char s1[100];
    char s2[100];
    char s3[100];
    char temp[100];
    scanf("%s%s%s",s1,s2,s3);
    if(strcmp(s1,s2)>0) strcpy(temp,s1),strcpy(s1,s2),strcpy(s2,temp);
    if(strcmp(s1,s3)>0) strcpy(temp,s1),strcpy(s1,s3),strcpy(s3,temp);
    if(strcmp(s2,s3)>0) strcpy(temp,s2),strcpy(s2,s3),strcpy(s3,temp); 
    printf("%s\n%s\n%s",s1,s2,s3);
    return 0;
}
2018-04-12 11:30:05
  • «
  • 1
  • »