这个题我弄了一下午,刚开始测试的结果是和例子一样,但是就是错误答案。看了下网上的答案才知道自己错在哪了:

它首先是按成绩排名的当成绩一样是就要原先的先后顺序排的。刚开始我一直以为都是按名字排的。哎。。。真的要有耐心才行啊。。。

代码:

#include"iostream"
#include"stdlib.h"
#include"string"
using namespace std;
typedef struct
{
 int chen;
 char cha1r[51];
 int a1;
} node;
node qq[310];
int chen1[310];
char char1[51];
int cp(const void* a,const void* b)
{
 if((*(node *)a).chen!=(*(node *)b).chen) return (*(node *)b).chen-(*(node *)a).chen;
 return (*(node *)a).a1-(*(node *)b).a1;
}
int main()
{
 int n,s1,s2;

 while(cin>>n)
 {
  s1=0;
  s2=0;
  for(int i=0;i<n;i++)
  {
   cin>>qq[i].cha1r>>qq[i].chen;
   qq[i].a1=i;
  }
  qsort(qq,n,sizeof(node),cp);
  for(int t=0;t<n;t++)
  {
   cin>>char1>>chen1[t];//后来输的
   if(strcmp(char1,qq[t].cha1r))  
             s1=1;
   if(t>0)
     if(chen1[t]>chen1[t-1])
      s2=1;
  } 
  if(s1==0)
    {
     
     cout<<"Right"<<endl;
     continue;
     }
  if(s2==0)
  {
   cout<<"Not Stable"<<endl;
   for(int k=0;k<n;k++)
     cout<<qq[k].cha1r<<' '<<qq[k].chen<<endl;
       continue;
  }
       
         cout<<"Error"<<endl;
   for(int r=0;r<n;r++)
     cout<<qq[r].cha1r<<' '<<qq[r].chen<<endl;
    
 }
 return 0;
}

 

posted on 2012-05-25 16:20  xinmenghuairi  阅读(313)  评论(0编辑  收藏  举报