标签:
input | output |
---|---|
4 Aurora Tiana Ariel Mulan |
5 |
解析:预处理一下各个名字在哪个case里面,然后再按照输入顺序移动即可。
AC代码:
#include <cstdio> #include <string> #include <iostream> using namespace std; int a[30]; int main(){ #ifdef sxk freopen("in.txt", "r", stdin); #endif //sxk for(int i=0; i<26; i++){ if(i == 'A' - 'A' || i == 'P' - 'A' || i == 'O' - 'A' || i == 'R' - 'A') a[i] = 1; else if(i == 'B' - 'A' || i == 'M' - 'A' || i == 'S' - 'A') a[i] = 2; else if(i == 'D' - 'A' || i == 'G' - 'A' || i == 'J' - 'A' || i == 'K' - 'A' || i == 'T' - 'A' || i == 'W' - 'A') a[i] = 3; else a[i] = 0; } int n; string s; while(scanf("%d", &n)==1){ int ans = 0, now = 1; for(int i=0; i<n ; i++){ cin>>s; ans += a[ s[0] - 'A' ] > now ? a[ s[0] - 'A' ] - now : now - a[ s[0] - 'A' ]; now = a[ s[0] - 'A' ]; } printf("%d\n", ans); } return 0; }
URAL 2023. Donald is a postman (预处理)
标签:
原文地址:http://blog.csdn.net/u013446688/article/details/44152617