题目
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200712112647642.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zOTA0MDk4MQ==,size_16,color_FFFFFF,t_70)
思路
- 用map映射string,double型来记录选手编号和举例靶心的距离d;
- 求d用根号下的平方和,sqrt函数。用double型便于比较;
- 输入时就记录最大值和最小值的编号和数值,最后用it迭代器查找输出。
AC代码
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
map<string,double> mp;
string s;
double d,x,y;
double max=0,min=9999;
string ma,mm;
for(int i=0;i<n;i++){
cin>>s>>x>>y;
d=sqrt(x*x+y*y);
if(d>max) {
max=d;
ma=s;
}
if(d<min) {
min=d;
mm=s;
}
mp[s]=d;
}
map<string,double> :: iterator it;
it=mp.find(mm); cout<<it->first;
cout<<' ';
it=mp.find(ma); cout<<it->first;
return 0;
}