解题思路:
直接使用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 人评分
C语言程序设计教程(第三版)课后习题4.9 (C++代码)浏览:2149 |
上车人数 (C语言代码)浏览:1184 |
C二级辅导-计负均正 (C语言代码)浏览:599 |
C语言训练-字符串正反连接 (C语言代码)浏览:622 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:625 |
C语言训练-尼科彻斯定理 (C语言代码)浏览:470 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:449 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:613 |
【计算球体积】 (C语言代码)浏览:1111 |
字符逆序 (C语言代码)浏览:650 |