不是 题目是不是搞反了 我本来80分,输入靠后的输出靠前,结果反一下就AC了

P1104 生日

crazy_shit @ 2024-03-09 15:10:28

#include<stdio.h>    
#include<stdlib.h>    
#include<string.h>  

struct Student {    
    char s[20];  
    int y;    
    int m;    
    int d;    
};    

int compare(const void *a, const void *b) {    
    const struct Student *studentA = *(const struct Student **)a;  
    const struct Student *studentB = *(const struct Student **)b;  
    if (studentA->y != studentB->y){
        return studentA->y - studentB->y;
        }
    else if(studentA->m != studentB->m){
        return studentA->m - studentB->m;
    }
    else if(studentA->d==studentB->d){
        return 1;
    }
    else{
        return studentA->d - studentB->d;    
    }
}

int main() {    
    int i, n;    
    scanf("%d", &n);    
    struct Student **info = (struct Student **)malloc(sizeof(struct Student *) * n);  

    for (i = 0; i < n; i++) {    
        info[i] = (struct Student *)malloc(sizeof(struct Student));  
        scanf("%19s %d %d %d", info[i]->s, &info[i]->y, &info[i]->m, &info[i]->d);  
    }    

    qsort(info, n, sizeof(struct Student *), compare);   
    for (i = 0; i < n; i++) {    
        printf("%s\n", info[i]->s);  
    }
    for (i = 0; i < n; i++) {    
        free(info[i]);    
    }    
    free(info);    

    return 0;    
}

by ZJNpeace @ 2024-05-09 15:50:01

一样,确实有问题


|