王贺


私信TA

用户名:MrSupW

访问量:83725

签 名:

LikeWind

等  级
排  名 15
经  验 21162
参赛次数 1
文章发表 198
年  龄 20
在职情况 学生
学  校 西北工业大学
专  业 软件工程

  自我简介:

What can not destory me only makes me stronger!

 

0.0分

6 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

为什么名字定义是char name[102]啊?如果其他地方完全不变,就这一处改成char name[100],系统就会判答案输出错误%50,求解
2020-02-09 16:24:14
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student{
		char name[101];
		int age;
		int score;
	}student;
int cmp(const void *a,const void *b){
	student *c=(student *)a;
	student *d=(student *)b;
	if(c->score!=d->score) return c->score<d->score?1:-1; 
	if(c->name!=d->name) return strcmp(c->name,d->name);
	return c->age<d->age?-1:1;
} 
int main(){
	int n;
	student a[1000];
	while((scanf("%d",&n))!=EOF){
	    getchar();
		for(int i=0;i<n;i++){
			scanf("%s %d %d",a[i].name,&a[i].age,&a[i].score);
			getchar();
		}
		qsort(a,n,sizeof(a[0]),cmp);
2020-02-07 17:12:38
  • «
  • 1
  • »