L1-056 猜數字 分數 20

Frodnx發表於2024-08-06
// 8'43"
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    double avg = 0;
    map<int,string> hash;
    int ans = 0;
    for(int i = 1; i <= n; ++ i)
    {
        string name;
        int num;
        cin >> name >> num;
        avg += (double) num;
        hash[num] = name;
        ans = num;
    }
    avg /= (double)n;
    avg /= 2;
    for(auto c : hash)
        if(fabs((double)ans - avg) > fabs((double)c.first - avg))
            ans = c.first;
            
    cout << (int)avg << " " << hash[ans];
    return 0;
}

相關文章