题解:AT_past20_b 電車の乗り換え
little_wusheng_ · · 题解
题目传送门
思路
思路很简单,只要统计 Takahashi 的数据就行。
运用结构体排序,最后输出时间最早的编号就行。
代码
代码:
#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;
}