#include<stdio.h>
struct time{
int year;
int month;
int day;
};
struct book{
char name[61];
int n;
struct time y;
int p;
int s;
};
int sort1(struct time*y1,struct time*y2);
void swap(struct book *s1,struct book *s2);
void comb1(struct book *s1,struct book *s2);
int main()
{
int n,i,loc,j;
scanf("%d",&n);
getchar();
struct book shu[n];
for(i=0;i<n;i++){
scanf("%s",shu[i].name);
scanf("%d",&shu[i].n);
scanf("%d",&shu[i].y.year);
scanf("%d",&shu[i].y.month);
scanf("%d",&shu[i].y.day);
scanf("%d",&shu[i].p);
scanf("%d",&shu[i].s);
}
for(loc=n-1;loc>0;loc--){
for(j=0;j<loc;j++){
comb1(&shu[j],&shu[j+1]);
}
}
for(i=0;i<n;i++){
printf("%s %d %d %d %d %d %d\n",shu[i].name,shu[i].n,shu[i].y.year,shu[i].y.month,shu[i].y.day,shu[i].p,shu[i].s);
}
return 0;
}
int sort1(struct time*y1,struct time*y2)
{
if(y1->year<y2->year){
return 1;
}
else if(y1->year==y2->year){
if(y1->month<y2->month){
return 1;
}
else if(y1->month==y2->month){
if(y1->day<y2->day){
return 1;
}
else if(y1->day==y2->day){
return 0;
}
}
}
}
void swap(struct book *s1,struct book *s2)
{
struct book temp;
temp=*s1;
*s1=*s2;
*s2=temp;
}
void comb1(struct book *s1,struct book *s2)
{
if((s1->p)>(s2->p)){
swap(s1,s2);
}
else if((s1->p)==(s2->p)){
if(sort1(&(s1->y),&(s2->y))==1){
swap(s1,s2);
}
else if(sort1(&(s1->y),&(s2->y))==0){
if(s1->n<s2->n){
swap(s1,s2);
}
else if(s1->n==s2->n){
if(s1->s<s2->s){
swap(s1,s2);
}
}
}
}
}
输出与案例相同,为什么只通过了一个测试点
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- stone_wangzx 2021-12-30 18:13关注
你的sort1函数中少一种返回值
int sort1(struct time* y1, struct time* y2) { if (y1->year < y2->year) { return 1; } else if (y1->year == y2->year) { if (y1->month < y2->month) { return 1; } else if (y1->month == y2->month) { if (y1->day < y2->day) { return 1; } else if (y1->day == y2->day) { return 0; } } } return 2;//少一种类型 }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥60 用visual studio编写程序,利用间接平差求解水准网
- ¥15 Llama如何调用shell或者Python
- ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
- ¥15 win10权限管理,限制普通用户使用删除功能
- ¥15 minnio内存占用过大,内存没被回收(Windows环境)
- ¥65 抖音咸鱼付款链接转码支付宝
- ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
- ¥15 blast算法(相关搜索:数据库)
- ¥15 请问有人会紧聚焦相关的matlab知识嘛?
- ¥15 网络通信安全解决方案