跳到正文

题解

题解:AT_past20_b 電車の乗り換え

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

文章信息

发布
2026年3月3日
收录
2026年3月8日
更新
2026年11月17日
篇幅
约 1 分钟

版本

  1. v1当前

题目传送门

思路

思路很简单,只要统计 Takahashi 的数据就行。

运用结构体排序,最后输出时间最早的编号就行。

代码

代码:

C++
#include"bits/stdc++.h"
using namespace std;

const int MAXN=1e5*2+5;
struct info{
	int time;
	int index;
};
struct info a[MAXN];
int n,cnt;
bool cmp(info a,info b){
	return a.time<b.time;//时间早的在前
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		string s;
		int t;
		cin>>s;
		scanf("%d",&t);
		if(s=="Takahashi"){//只统计Takahashi
			cnt++;
			a[cnt].time=t;
			a[cnt].index=i;
		}
	}
	sort(a+1,a+cnt+1,cmp);
	printf("%d\n",a[1].index);//输出编号
	return 0;
}
原文