跳到正文

个人记录

P9858 题解

halamadrid_15约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年2月7日
收录
2025年12月12日
更新
2026年9月30日
篇幅
约 1 分钟

版本

  1. v1当前

新方法:结构体排序。

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

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

C++
#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;
}
原文