关于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;
}
#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;
}
相关文章推荐
- HDU1872 稳定排序
- hdu1872 稳定排序
- HDU1872 稳定排序
- hdu1872 稳定排序
- 【HDU1872】稳定排序(sort)
- 关于一些服务相关的常用command
- jsp、servlet关于中文问题再谈
- 关于anothr
- 关于vector的一点源码分析
- 关于 "CS0016: 未能写入输出文件" 的解决办法 编译器错误信息: CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\listenleaks\ae3daa38\e9fdb67
- 关于蔡勒公式的程序实现的几点说明
- 关于业务用例抽象问题对网友的回复
- 关于SCCM客户端1603错误
- 几个关于web开发资源的站点
- 关于管理弹性的把握 推荐
- [继续讨论]关于Windows PE和.net assembly的加载
- 关于通用计算
- 收藏的关于JS的一些文章
- 【分享】关于a标签的4个伪类
- 关于期权行权培训的一些知识点