| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 299 人关注过本帖
标题:关于一道c++题目的疑惑
只看楼主 加入收藏
妙源清君
Rank: 2
等 级:论坛游民
帖 子:7
专家分:10
注 册:2011-7-10
结帖率:0
收藏
 问题点数:0 回复次数:0 
关于一道c++题目的疑惑
Description
Excel可以对一组纪录按任意指定列排序。现请你编写程序实现类似功能。
Input
测试输入包含若干测试用例。每个测试用例的第1行包含两个整数 N (<=100000) 和 C,其中 N 是纪录的条数,C 是指定排序的列号。以下有 N
行,每行包含一条学生纪录。每条学生纪录由学号(6位数字,同组测试中没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩(闭区间[0, 100]内的整数)组成,每个项目间用1个空格隔开。当读到 N=0 时,全部输入结束,相应的结果不要输出。
Output
对每个测试用例,首先输出1行“Case i:”,其中 i 是测试用例的编号(从1开始)。随后在 N 行中输出按要求排序后的结果,即:当 C=1 时,按学号递增排序;当 C=2时,按姓名的非递减字典序排序;当 C=3
时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。
Sample Input
3 1
000007 James 85
000010 Amy 90
000001 Zoe 60
4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98
4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90
0

我的代码,提交为什么是Output Limit Exceed

#include<stdio.h>
#include<stdlib.h>
#include <string.h>
struct student
        { char num[10];
          char name[10];
          int score;
        };
struct student USER[100000];
int N;
int comp1(void const *a,void const *b)
{  
    student *c=(student *)a;
    student *d=(student *)b;   
    return strcmp(c->num,d->num);
}
int comp2(void const *a,void const *b)
{   
    student *c=(student *)a;
    student *d=(student *)b;
    int t;
    t=strcmp(c->name,d->name);
    if(t!=0)  
        return t;
    else {  return strcmp(c->num,d->num); }
}
int comp3(void const *a,void const *b)
{   
    student *c=(student *)a;
    student *d=(student *)b;
    if(c->score!=d->score)
        return c->score-d->score;
    else {  return strcmp(c->num,d->num); }
}
int main()
{   
    int C,i,j,n=1;
    while(scanf("%d",&N)!=0)
    {  scanf("%d",&C);
    for(i=0;i<N;i++)
        scanf("%s%s%d",USER[i].num,USER[i].name,&USER[i].score);
    switch(C)
    {case 1:  
         qsort(USER,N,sizeof(student),comp1);break;
     case 2:
         qsort(USER,N,sizeof(student),comp2);break;
     case 3:
         qsort(USER,N,sizeof(student),comp3);break;
    }
    printf("Case %d:\n",n++);
    for(i=0;i<N;i++)
    printf("%s %s %d\n",USER[i].num,USER[i].name,USER[i].score);
    }
    return 0;
}

搜索更多相关主题的帖子: 编写程序 字符串 Excel 项目 姓名 
2011-07-11 23:10
快速回复:关于一道c++题目的疑惑
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012064 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved