hdu 1872 稳定排序
???????? 這個題我弄了一下午,剛開始測試的結果是和例子一樣,但是就是錯誤答案。看了下網上的答案才知道自己錯在哪了:
它首先是按成績排名的當成績一樣是就要原先的先后順序排的。剛開始我一直以為都是按名字排的。哎。。。真的要有耐心才行啊。。。
代碼:
#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;
}
?
轉載于:https://www.cnblogs.com/xinmenghuairi/archive/2012/05/25/2518239.html
總結
以上是生活随笔為你收集整理的hdu 1872 稳定排序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用nagios监控oracle
- 下一篇: Js 获取当前页面的高度