当前位置: 代码迷 >> 综合 >> HDU 1862 EXCEL排序
  详细解决方案

HDU 1862 EXCEL排序

热度:34   发布时间:2023-12-05 06:30:57.0
//太简单了,没什么好说的
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
struct node 
{int num;char name[10];int A;
}a[100005];
int cmp(node a,node b)
{return a.num<b.num;
}
int cmpp(node a,node b)
{if(strcmp(a.name,b.name)==0)return a.num<b.num;elsereturn strcmp(a.name,b.name)<0;
}
int cmppp(node a,node b)
{if(a.A==b.A)return a.num<b.num;elsereturn a.A<b.A;
}
int main(int argc, char *argv[])
{int t=1;int n,c;int i,j;while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));scanf("%d",&c);if(n==0&&c==0)break;for(i=0;i<n;i++){scanf("%d %s %d",&a[i].num,a[i].name,&a[i].A);}if(c==1){sort(a,a+n,cmp);printf("Case %d:\n",t++);for(i=0;i<n;i++)printf("%06d %s %d\n",a[i].num,a[i].name,a[i].A);}else if(c==2){printf("Case %d:\n",t++);sort(a,a+n,cmpp);for(i=0;i<n;i++)printf("%06d %s %d\n",a[i].num,a[i].name,a[i].A);}        else if(c==3){printf("Case %d:\n",t++);sort(a,a+n,cmppp);for(i=0;i<n;i++)printf("%06d %s %d\n",a[i].num,a[i].name,a[i].A);}                    }    return 0;
}
//Start-ZJ
//2017/11/30/12:07

 

  相关解决方案