Open Rohyoohyun opened 2 months ago
typedef struct { int age; char name[101]; } Person;
int compare(const void a, const void b) { Person A = (Person )a; Person B = (Person )b; return A->age - B->age; }
int main() { int n; scanf("%d", &n);
Person *people = (Person *)malloc(n * sizeof(Person)); for(int i = 0; i < n; i++){ scanf("%d", &people[i].age); getchar(); fgets(people[i].name, 101, stdin); size_t len = strlen(people[i].name); if (len > 0 && people[i].name[len-1] == '\n') { people[i].name[len-1] = '\0'; } } qsort(people, n, sizeof(Person), compare); for(int i = 0; i < n; i++, puts("")) printf("%d %s", people[i].age, people[i].name); free(people); return 0;
}
include
include
include
typedef struct { int age; char name[101]; } Person;
int compare(const void a, const void b) { Person A = (Person )a; Person B = (Person )b; return A->age - B->age; }
int main() { int n; scanf("%d", &n);
}