关于hdu1872的稳定排序

#include<stdio.h>
#include<string.h>

typedef struct student
{
      char name[60];
      int score;
}ss;

int main()
{
     int N,i,j,flag,flag1,flag2;
     ss stu1[500],stu2[500];
     char temp[60];
     int tmp;
     while(scanf("%d",&N)!=EOF)
     {
          i=0;
          while(i<N)
          {
               scanf("%s %d",&stu1[i].name,&stu1[i].score);
               i++;
          }
          i=0;
          while(i<N)
          {
               scanf("%s %d",&stu2[i].name,&stu2[i].score);
               i++;
          }
          for(i=0;i<N;i++)
          {
               flag=0;
               for(j=0;j<N-1-i;j++)
               {
                    if(stu1[j].score<stu1[j+1].score)
                    {
                           strcpy(temp,stu1[j].name);
                              tmp=stu1[j].score;
                           strcpy(stu1[j].name,stu1[j+1].name);
                              stu1[j].score=stu1[j+1].score;
                           strcpy(stu1[j+1].name,temp);
                              stu1[j+1].score=tmp;
                              flag=1;
                    }
               }
               if(flag==0)
                 break;
          }
          flag1=0;
          flag2=0;
          i=0;
          while(i<N)
          {
               if(strcmp(stu1[i].name,stu2[i].name)!=0)
               {
                    flag1=1;
               }
               if(stu1[i].score!=stu2[i].score)
               {
                    flag2=1;
               }
               i++;
          }
          if(flag1==0)
          {
               printf("Right\n");
          }
          else
          {
             if(flag2==0)
            {
               printf("Not stable\n");
               i=0;
              while(i<N)
               {
                    printf("%s %d\n",stu1[i].name,stu1[i].score);
                    i++;
               }
            }
            else
            {
               printf("Error\n");
                i=0;
                 while(i<N)
                {
                    printf("%s %d\n",stu1[i].name,stu1[i].score);
                    i++;
                }
            }
          }
     }
     return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值