您的位置:首页 > 其它

关于hdu1872的稳定排序

2012-10-28 22:08 162 查看
#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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: