肖英豪


私信TA

用户名:dotcpp0602020

访问量:2748

签 名:

睡大觉

等  级
排  名 2144
经  验 2365
参赛次数 7
文章发表 61
年  龄 0
在职情况 学生
学  校 内蒙古工业大学
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#include <stdio.h>
#include <string.h>
int main()
{
    int n = 0, b[25] = {0};
    char a[25][25] = {0}, s[25] = {0};
    scanf("%d", &n);
   
    for (int i = 0; i < n; i++)
        scanf("%s %d", a[i], &b[i]);

    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < n - 1 - i; j++)
        {
            if(b[j] < b[j + 1]) 
            {
                int t = b[j];
                b[j] = b[j + 1];
                b[j + 1] = t;

                strcpy(s, a[j]);
                strcpy(a[j], a[j + 1]);
                strcpy(a[j + 1], s);
            }
            else if (b[j] == b[j + 1])
            {
                if (strcmp(a[j], a[j + 1]) > 0)
                {
                    strcpy(s, a[j]);
                    strcpy(a[j], a[j + 1]);
                    strcpy(a[j + 1], s);
                }
            }
        }
    }

    for (int i = 0; i < n; i++)
        printf("%s %d\n", a[i], b[i]);

    return 0;
}


 

0.0分

3 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区