解题思路:
直接使用qsort函数排序,快的不得了。
参考代码:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define ll long long struct pp{ char a[100]; char b[100]; ll n; ll m; }; struct pp p[1001]; int gg(const void *x,const void *y){ struct pp *a=(struct pp *)x; struct pp *b=(struct pp *)y; return a->m-b->m; } int main (){ ll i,j; ll n,m; scanf("%lld",&n); for(i=0;i<n;i++){ scanf("%s %s %lld %lld",&p[i].a,&p[i].b,&p[i].n,&p[i].m); } qsort(p,n,sizeof(p[0]),gg); for(i=0;i<n;i++){ printf("%s %s %lld %lld\n",p[i].a,p[i].b,p[i].n,p[i].m); } return 0; }
0.0分
157 人评分
2005年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:724 |
第一浏览:884 |
C二级辅导-同因查找 (C语言代码)浏览:572 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)scanf后面加个getchar(),收掉回车符,就可以用gets了浏览:1157 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:690 |
【出圈】 (C语言代码)浏览:806 |
简单的a+b (C语言代码)浏览:713 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:561 |
WU-printf基础练习2 (C++代码)浏览:2013 |
1024题解浏览:842 |