hiho一下 第213周:Boarding Passes

描述

Long long ago you took a crazy trip around the world. You can not remember which cities did you start and finish the trip.  Luckily you have all the boarding passes. Can you find out the starting city and ending city?

输入

The first line contains a number N denoting the number of boarding passes.  (1 <= N <= 100)

The following N lines each contain a pair of cities (the city name consists of no more than 10 capital letters)

It is guaranteed that there is always a valid solution.

输出

The starting and ending cities separated by a space.

样例输入

4  
SFO HKG  
PVG BOS  
HKG ABC  
ABC PVG

样例输出

SFO BOS

题解:字符串基础操作

#include<bits/stdc++.h>
using namespace std;
map<string,int>line1,line2;
int t;
string sr[205],ans1,ans2;
int main()
{
    scanf("%d",&t);
    for (int i=0;i<2*t;i+=2){
    	cin>>sr[i]>>sr[i+1];//不能用scanf来输入string 
    	line1[sr[i]]++;
    	line2[sr[i+1]]++;
	}
	for (int i=0;i<2*t;i++){
		if (line2[sr[i]]-line1[sr[i]]==1)
            ans1=sr[i];
        if (line1[sr[i]]-line2[sr[i]]==1)
            ans2=sr[i];
	}
	cout<<ans2<<" "<<ans1<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值