1 条题解

  • 0
    @ 2025-4-12 22:03:05

    C :

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char t[100],a[100],b[100],c[100];
        gets(a);gets(b);gets(c);
        if(strcmp(a,b)>0){strcpy(t,a);strcpy(a,b);strcpy(b,t);}
        if(strcmp(a,c)>0){strcpy(t,a);strcpy(a,c);strcpy(c,t);}
        if(strcmp(b,c)>0){strcpy(t,b);strcpy(b,c);strcpy(c,t);}
        printf("%s\n%s\n%s\n",a,b,c);
        return 0;
    }
    
    

    C++ :

    #include<iostream>
    #include <algorithm>
    using namespace std;
    struct gax{
        string s;
    }str[5];
    int compare(struct gax s1,struct gax s2)
    {
        return s1.s<s2.s;
    }
    int main()
    {
        for(int i=0;i<3;i++)
            cin>>str[i].s;
        sort(str,str+3,compare);
        for(int i=0;i<3;i++)
            cout<<str[i].s<<endl;
    }
    
    
    • 1

    C语言程序设计教程(第三版)课后习题10.2

    信息

    ID
    2730
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者