C题解 1082 射击比赛 (20 分)
作者:互联网
原题
https://pintia.cn/problem-sets/994805260223102976/problems/994805260990660608
代码
今天正式用c来刷PAT了,java遭不住,同样的思路不用工具类,一个几百毫秒,一个几毫米。难搞难搞。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
int result[1]={0};//记录最大值最小值时的编号
int count = 0;
//读入
scanf("%d",&count);
int max=0,min=200;
for (int i = 0; i < count; i++)
{
int id,x,y;
float distance;
scanf("%d",&id);
scanf("%d",&x);
scanf("%d",&y);
distance=sqrt(x*x+y*y);
if(distance>=max){
max=distance;
result[0]=id;
}
if(distance<=min){
min=distance;
result[1]=id;
}
}
printf("%04d %04d",result[1],result[0]);
return 0;
}
标签:count,distance,20,1082,int,题解,scanf,include,id 来源: https://www.cnblogs.com/InifiteVictory/p/15579013.html