杭电 1862 excel

http://acm.hdu.edu.cn/showproblem.php?pid=1862

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
using namespace std;

struct student{
    int node;
    string name;
    int score;
};

bool cmp1(student a,student b)
{
    return a.node<b.node;
}
bool cmp2(student a,student b)
{
    if(a.name==b.name)
    return a.node<b.node;
    else
    return a.name<b.name;
}
bool cmp3(student a,student b)
{
    if(a.score==b.score)
    return a.node<b.node;
    return a.score<b.score;
}
student s[100001];
int main()
{
    int n,c,k=1;

    while(cin>>n>>c,n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>s[i].node>>s[i].name>>s[i].score;
        }

       switch(c)
       {
           case 1:
           {
               sort(s,s+n,cmp1);
               break;
           }
           case 2:
           {
               sort(s,s+n,cmp2);
               break;
           }
           case 3:
           {
               sort(s,s+n,cmp3);
               break;
           }
       }
       cout<<"Case "<<k++<<":"<<endl;
       for(int i=0;i<n;i++)
        {
            cout<<setw(6)<<setfill('0')<<s[i].node<<" "<<s[i].name<<" "<<s[i].score<<endl;
        }
    }
    return 0;
}
这里有问题    提交不了      下面是ac代码
 
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
//#include <cmath>
using namespace std;

struct Student
{
    char name[20];
    char num[20];
    int score;
} stu[100005];

bool cmp1(Student x,Student y)
{
    if( strcmp(x.num , y.num) > 0 )
        return 0;
   else
        return 1;
}

bool cmp2(Student x,Student y)
{
   if( strcmp(x.name , y.name) > 0 )
        return 0;
    else if(strcmp(x.name , y.name) == 0)
    {
               if( strcmp(x.num , y.num) > 0 )
           return 0;
    }
    return 1;
    }

bool cmp3(Student x,Student y)
{
    if( x.score>y.score )
        return 0;
    else if(x.score==y.score)
    {
       if( strcmp(x.num , y.num) > 0 )
                   return 0;
    }
    return 1;
}

int main()
{
    int n,c,i,cnt = 1;
    while(cin >> n >> c && n != 0 && c != 0)
    {
        for(i = 0; i<n; i++)
            scanf("%s%s%d",stu[i].num,stu[i].name,&stu[i].score);
        if(c == 1)
            sort(stu,stu+n,cmp1);
        else if(c == 2)
            sort(stu,stu+n,cmp2);
        else if (c == 3)
            sort(stu,stu+n,cmp3);
        printf("Case %d:\n",cnt++);
        for(i = 0; i<n; i++)
            printf("%.6s %s %d\n",stu[i].num,stu[i].name,stu[i].score);
    }
    return 0;
}



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值