View Code of Problem 3861

#include<stdio.h>
#include<string.h>
#include<math.h>
/*数据范围保证1 <= T <= 5, 1 <= n <= 1000, 1 <= ai <= 1000。
Output:*/ 
/*注意事项双精度*/ 
typedef struct phone
{
	char name[21];//每行给出当前这部手机的名称name(1<=|name|<=20)
	double a;//性能分数p(1<=p<=100000)s
	double b;//价格q(1<=q<=10000)
	double c;
}phone;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--) //第一行给出一个整数T(1<=T<=100),表示测试数据的数目。
	{	
		int n;
		double x,w;//每次都要初始化 
		scanf("%d",&n);//第一行给出一个整数n(1<=n<=100)
		phone p[n];
		for(int i=0;i<n;i++)
		{
			scanf("%s %lf %lf",&p[i].name,&x,&w);
			p[i].a=x,p[i].b=w;
			p[i].c=p[i].a/p[i].b;
		}
		for(int i=n-1;i>=0;i--)
		{	
			for(int j=0;j<i;j++)
			{
				if(p[j].c<p[j+1].c)
				{
					phone temp=p[j];
					p[j]=p[j+1];
					p[j+1]=temp;
				}
			}
		}
		/*输出*/
		int k=1;//每次都要初始化 
//		if(t!=0)
		for(int i=0;i<n;i++) 
		{	
			printf("%d %s %.0lf %.0lf\n",k++,p[i].name,p[i].a,p[i].b);
		}
//		else
//		{
//		for(int i=0;i<n;i++) 
//		{	if(i!=n-1)
//		{
//			printf("%d %s %lf %lf\n",k++,p[i].name,p[i].a,p[i].b);
//		}
//			else
//			{
//				printf("%d %s %lf %lf",k++,p[i].name,p[i].a,p[i].b);	
//			}
//		}	
//		}
	}
	return 0; 
}

Double click to view unformatted code.


Back to problem 3861