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 #include #include #include #include #include #include #include #include #define LL long long #define eps 1e-8 #define maxn 550 #define mod 100000007 #define inf 0x3f3f3f3f #define IN freopen("in.txt","r",stdin); using namespace std;

int a[300];

int main(int argc, char const *argv[])
{
//IN;

a['A'] = a['P'] =  a['O'] = a['R'] =  1;
a['B'] = a['M'] =  a['S'] = 2;
a['D'] = a['G'] =  a['J'] = a['K'] = a['T'] = a['W'] =  3;

int n;
while(scanf("%d", &n) != EOF)
{
    char str[300];
    int cur = 1;
    int ans = 0;
    for(int i=1; i<=n; i++) {
        scanf("%s", str);
        int tmp = a[str[0]];
        ans += abs(tmp-cur);
        cur = tmp;
    }

    printf("%d\n", ans);
}

return 0;

}

posted @ 2016-08-07 12:20  Sunshine_tcf  阅读(360)  评论(0编辑  收藏  举报