P9858 题解

· · 个人记录

新方法:结构体排序。

我们可以把输入的城市名称和温度存到结构体数组 f 里。

然后根据结构体中的 t 排序,最后输出 t 最小的 s 即可。

#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node{
    string s;
    int t;
}f[100010];
bool cmp(const node &a,const node &b){
    return a.t<b.t;
}
signed main(){
    ios::sync_with_stdio(false);
    int k = 1;
    while(1){
        cin>>f[k].s>>f[k].t;
        if(f[k].s == "Waterloo"){
            break;
        }
        k++;
    }
    sort(f+1,f+k+1,cmp);
    cout<<f[1].s;
    return 0;
}