一群人坐在一起,每人猜一个 100 以内的数,谁的数字最接近大家平均数的一半就赢。本题就要求你找出其中的赢家。
输入在第一行给出一个正整数N(≤104)。随后 N 行,每行给出一个玩家的名字(由不超过8个英文字母组成的字符串)和其猜的正整数(≤ 100)。
在一行中顺序输出:大家平均数的一半(只输出整数部分)、赢家的名字,其间以空格分隔。题目保证赢家是唯一的。
- 7
- Bob 35
- Amy 28
- James 98
- Alice 11
- Jack 45
- Smith 33
- Chris 62
22 Amy
这题结构体排序就行了,掌握整个模拟过程,一个cmp就搞定了
- #include
- #include
- #include
- using namespace std;
- #define IOO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- //const int maxLine=5000+10;
- //#define ll long long int
- #define int long long int
- #define um unordered_map
- #define vec vector
- const int maxLine=1e4+10;
- //#define DEBUG true
- //int n,m,k;
-
- //int arr[maxLine];
-
- //调用可以进行重定向
- void initRedict() {
- #ifdef DEBUG
- cout<<"执行重定向"<
- //重定向输入
- freopen("../redict/demo/demo_in.txt","r",stdin);
- #endif
- }
- string mystr;
- int n;
- int len,indexx;
- int startx,starty;
- char arr[maxLine][maxLine];
-
- struct student {
- string name;
- double score;
- double rankNums;
- };
- struct student ttt[maxLine];
-
- bool cmp(struct student a,struct student b){
- return a.rankNums
- }
- signed main() {
- int n;
- cin>>n;
- getchar();
- double sum=0;
- for(int i=0;i
- cin>>ttt[i].name>>ttt[i].score;
- sum+=ttt[i].score;
- }
- sum/=n;
- sum/=2;
- for(int i=0;i
fabs(sum-ttt[i].score); - sort(ttt,ttt+n,cmp);
- cout<<(int)(sum)<<" "<
0].name< -
-
- return 0;
- }
-
相关阅读:
信奥一本通1187:统计字符数
MySQL高级学习笔记
雨水情监测及视频监控解决方案 水库雨水情自动测报系统 介绍 功能 特点
js基础笔记学习280蛇流畅运动
命名空间和作用域
统计套利—配对交易策略
面向对象设计原则-一句话总结设计原则
分享从零开始学习网络设备配置--任务3.5 使用静态路由实现网络连通
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
selenium.chrome怎么写扩展拦截或转发请求?
-
原文地址:https://blog.csdn.net/m0_72678953/article/details/134322692