#P3405. [USACO16DEC] Cities and States S
[USACO16DEC] Cities and States S
题目描述
To keep his cows intellectually stimulated, Farmer John has placed a large map of the USA on the wall of his barn. Since the cows spend many hours in the barn staring at this map, they start to notice several curious patterns. For example, the cities of Flint, MI and Miami, FL share a very special relationship: the first two letters of "Flint" give the state code ("FL") for Miami, and the first two letters of "Miami" give the state code ("MI") for Flint.
Let us say that two cities are a "special pair" if they satisfy this property and come from different states. The cows are wondering how many special pairs of cities exist. Please help them solve this amusing geographical puzzle!
为了训练奶牛们的智力,Farmer John 在谷仓的墙上放了一张美国地图。由于奶牛在谷仓里花了很多时间看这张地图,他们开始注意到一些奇怪的关系。例如,Flint 的前两个字母就是 Miami 所在的 FL
州,Miami 的前两个字母则是 Flint 所在的 MI
州。
确切地说,对于两个城市,它们的前两个字母互为对方所在州的名称。
我们称两个城市是一个一对“特殊的”城市,如果他们具有上面的特性,并且来自不同的省。奶牛想知道有多少对“特殊的”城市存在。请帮助他们解决这个有趣的地理难题!
输入格式
The first line of input contains (), the number ofcities on the map.
The next lines each contain two strings: the name of a city (a string of at least 2 and at most 10 uppercase letters), and its two-letter state code (a string of 2 uppercase letters). Note that the state code may be something like ZQ, which is not an actual USA state. Multiple cities with the same name can exist, but they will be in different states.
第一行一个正整数 ,表示地图上的城市的个数。
接下来 行,每行两个字符串,分别表示一个城市的名称(个大写字母)和所在州的代码( 个大写字母)。可能出现类似 ZQ
的州代码,即并不真的是美国的一个州的代码。同一个州内不会有两个同名的城市。
输出格式
Please output the number of special pairs of cities.
输出特殊的城市对数。
6
MIAMI FL
DALLAS TX
FLINT MI
CLEMSON SC
BOSTON MA
ORLANDO FL
1