求代码

zhang127025 2010-12-16 09:34:26
给出n个学生的考试成绩表,每条信息由学号姓名和分数组成。
要求:1,首先按学号排序
2,再按分数排序,并要求分数相同的任然保持按学号排序
答案要求:
写出整个程序代码
...全文
110 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hbprotoss 2011-01-20
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhang127025 的回复:]

我不是北理的,但我有朋友在北理。
呵呵、、、、
谢谢帮忙!!!!
[/Quote]

网络教室原题,我直接把我做的代码贴过来了,,,,,,
zhang127025 2010-12-16
  • 打赏
  • 举报
回复
我不是北理的,但我有朋友在北理。
呵呵、、、、
谢谢帮忙!!!!
jsjygm 2010-12-16
  • 打赏
  • 举报
回复
hbprotoss 2010-12-16
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINEMAX 30
#define MAX 50
#define MAX_NAME 21//名字不超过20个字符
struct Student
{
char name[MAX_NAME];
int mark;
};

void AnalyzeString(struct Student *stu, char *str)
{
int i=0;//下标
for(i=0; str[i] != '\0'; i++)
{
//标记逗号
if(str[i] == ',')
{
str[i] = '\0';//方便字符串提取
break;
}
}

//提取姓名
strcpy(stu->name, str);
//提取成绩
stu->mark = atoi(&str[i+1]);
}

//用冒泡法排序
void Sort(struct Student stu[], int n)
{
int i,j;
struct Student tmp;
memset(&tmp, 0, sizeof(struct Student));
for(i = 0; i < n-1; i++)
{
for(j = n-1; j > i; j--)
{
if(stu[j].mark > stu[j-1].mark)
{
memcpy(&tmp, &stu[j], sizeof(struct Student));
memcpy(&stu[j], &stu[j-1], sizeof(struct Student));
memcpy(&stu[j-1], &tmp, sizeof(struct Student));
}
}
}
}
void main()
{
struct Student stu[MAX];//学生
char tmpLine[LINEMAX];//临时储存输入的一行
int n=0;//总人数
int i=0;//下标
memset(stu, 0, MAX * sizeof(struct Student));
memset(tmpLine, '\0', LINEMAX * sizeof(char));

scanf("%d", &n);
getchar();
for(i=0;i<n;i++)
{
gets(tmpLine);
AnalyzeString(&stu[i], tmpLine);
}

Sort(stu, n);

for(i=0; i<n; i++)
{
printf("%s,%d\n", stu[i].name, stu[i].mark);
}
}
zhang127025 2010-12-16
  • 打赏
  • 举报
回复
不好意思,可能表述有问题,但确实很急!!!!
hbprotoss 2010-12-16
  • 打赏
  • 举报
回复
难道你是北理的= =
licaiyuren 2010-12-16
  • 打赏
  • 举报
回复
说啥好呢,求代码。。。。
不过,还是有人给你代码的。。。。就为了刷分

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧