Gym 100507L Donald is a postman (水题)
Donald is a postman
题目链接:
http://acm.hust.edu.cn/vjudge/contest/126546#problem/L
Description
Donald Duck works as a postman for the Walt Disney Studios. He delivers children’s letters from all over the world to his friends, which are cartoon characters. The Studios has three cases for the letters, with nine sections in each case. Every section has the name of the receiver on it. All cases stand in a row as it is shown at the picture below. Donald Duck have brought 𝑛 letters today. Initially, he stands near the leftmost case. He has to make one step to go to the neighboring case or to the previous one. How many steps will he make until he puts all the letters into the respective sections, if he does this in the order they are in his bag?Input
The first line contains an integer 𝑛 that is the amount of letters in Donald’s bag (1 ≤ 𝑛 ≤ 1 000). The following 𝑛 lines contain receivers of the letters in the order they are in the bag.Output
Output the number of steps Donald should make to put all the letters into the cases.Examples
test answer 4 Aurora Tiana Ariel Mulan 5##题意: 三个盒子上有9个不同的信箱. 相邻盒子之间的距离为1. 要将n封信依次放入信箱,求总共需要多少步.
##题解: 看图可知不同盒子上名字的开头字母都不一样. 所以只记录和比较开头字母即可.
##代码: ``` cpp #include