View Code of Problem 3861

#include <stdio.h>
#include <math.h>
#include <string.h>
struct iphone{
	char name[20];
	float p;
	float q;
};

int main(){
	int t,i,j;
	int a[100]; 
	scanf("%d",&t);
	int n;
	while(t--){
		struct iphone list[100],temp;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%s %f %f",list[i].name,&list[i].p,&list[i].q);
		}
		for(i=0;i<n-1;i++){
			for(j=0;j<n-1-i;j++){
				if(list[j].p/list[j].q<list[j+1].p/list[j+1].q){
					temp=list[j];
					list[j]=list[j+1];
					list[j+1]=temp;
				}
			}
		}
		
		for(i=1;i<=n;i++){
			printf("%d %s %.f %.f\n",i,list[i-1].name,list[i-1].p,list[i-1].q);
		}
		
	}
	
	
	
	
	
	
	
}

Double click to view unformatted code.


Back to problem 3861