• L1-056 猜数字


    一群人坐在一起,每人猜一个 100 以内的数,谁的数字最接近大家平均数的一半就赢。本题就要求你找出其中的赢家。

    输入格式:

    输入在第一行给出一个正整数N(≤104)。随后 N 行,每行给出一个玩家的名字(由不超过8个英文字母组成的字符串)和其猜的正整数(≤ 100)。

    输出格式:

    在一行中顺序输出:大家平均数的一半(只输出整数部分)、赢家的名字,其间以空格分隔。题目保证赢家是唯一的。

    输入样例:

    1. 7
    2. Bob 35
    3. Amy 28
    4. James 98
    5. Alice 11
    6. Jack 45
    7. Smith 33
    8. Chris 62

    输出样例:

    22 Amy

     这题结构体排序就行了,掌握整个模拟过程,一个cmp就搞定了

    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. #define IOO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    6. //const int maxLine=5000+10;
    7. //#define ll long long int
    8. #define int long long int
    9. #define um unordered_map
    10. #define vec vector
    11. const int maxLine=1e4+10;
    12. //#define DEBUG true
    13. //int n,m,k;
    14. //int arr[maxLine];
    15. //调用可以进行重定向
    16. void initRedict() {
    17. #ifdef DEBUG
    18. cout<<"执行重定向"<
    19. //重定向输入
    20. freopen("../redict/demo/demo_in.txt","r",stdin);
    21. #endif
    22. }
    23. string mystr;
    24. int n;
    25. int len,indexx;
    26. int startx,starty;
    27. char arr[maxLine][maxLine];
    28. struct student {
    29. string name;
    30. double score;
    31. double rankNums;
    32. };
    33. struct student ttt[maxLine];
    34. bool cmp(struct student a,struct student b){
    35. return a.rankNums
    36. }
    37. signed main() {
    38. int n;
    39. cin>>n;
    40. getchar();
    41. double sum=0;
    42. for(int i=0;i
    43. cin>>ttt[i].name>>ttt[i].score;
    44. sum+=ttt[i].score;
    45. }
    46. sum/=n;
    47. sum/=2;
    48. for(int i=0;ifabs(sum-ttt[i].score);
    49. sort(ttt,ttt+n,cmp);
    50. cout<<(int)(sum)<<" "<0].name<
    51. return 0;
    52. }

  • 相关阅读:
    Python条件语句+字典
    BEVerse 中数据集预处理代码浅析
    初识ElasticSearch
    虚拟局域网
    docker安装redis
    如何快速本地搭建悟空CRM结合内网穿透工具高效远程办公
    kubeadm 部署的 k8s 增加 ip 并重新生成证书
    php反序列化漏洞
    mysql与jdbc笔记
    python实现彭曼公式计算潜在蒸散发ET0
  • 原文地址:https://blog.csdn.net/m0_72678953/article/details/134322692