View Code of Problem 3861

#include<stdio.h>

typedef struct telephone{
	char name[30];
	int p;
	int q;
	double xjb;
}telephone;

int cmp(const void *a,const void *b){
	return (*(telephone *)b).xjb-(*(telephone *)a).xjb;
}

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,i;
		scanf("%d",&n);
		telephone P[n];
		for(i=0;i<n;i++){
			scanf("%s %d %d",&P[i].name,&P[i].p,&P[i].q);
			P[i].xjb=(double)P[i].p/(double)P[i].q;
		}
		qsort(P,n,sizeof(P[0]),cmp);
		for(i=0;i<n;i++){
			printf("%s %d %d\n",P[i].name,P[i].p,P[i].q);
		}
	}
}

Double click to view unformatted code.


Back to problem 3861