⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2101197_wa.c

📁 北大大牛代码 1240道题的原代码 超级权威
💻 C
字号:
# include <stdio.h>
# include <string.h>
# include <stdlib.h>

struct node
{
    int id;
    long num;
    long p;
}com[1001], TMP;

struct Node
{
    long p;
}Tmp[1001];

int cmp(const void *a,const void *b)
{
    struct node *aa = (struct node *)a;
    struct node *bb = (struct node *)b;
    if(aa->p==bb->p)
       return aa->id-bb->id;
    else
       return aa->p-bb->p>0?1:-1;
}

void input()
{
    char tmp[10];
    long num, p;
    int i, j, l, K, T;
    
    l = 0;
    while(scanf("%s",tmp)==1&&strcmp(tmp,"#")!=0)
    {
        scanf("%ld%ld",&num,&p);  
        com[l].num = num;
        com[l].p = p;
        com[l].id = l;
        Tmp[l].p = p;
        l++;
    }
    qsort(com,l,sizeof(com[0]),cmp);
    scanf("%d",&K);
    T = l;
    for(i = 0; i < K; i++)
    {
        printf("%ld\n",com[0].num);
        com[0].p += Tmp[com[0].id].p;
        for(j = 1; j < l;j++)
        {
            if(com[j-1].p>com[j].p)//||(com[j-1].p==com[j].p&&com[j-1].id>com[j].id)
            {
                TMP = com[j];
                com[j] = com[j-1];
                com[j-1] =TMP;
            }
            else
               break;
        }
    }
}

int main()
{
    input();
    //system("pause");
    return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -