2023. Donald is a postman

Time limit: 1.0 second
Memory limit: 64 MB

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 n 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 n that is the amount of letters in Donald’s bag (1 ≤ n ≤ 1 000). The following n 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.

Sample

input output
4
Aurora
Tiana
Ariel
Mulan
5
Problem Author: Alex Samsonov
Problem Source: NEERC 2014, Eastern subregional contest
 
 
 
 
 
 #include <bits/stdc++.h>
using namespace std; string str[][]= {{"Alice","Ariel","Aurora","Phil","Peter","Olaf","Phoebus","Ralph","Robin"},
{"Bambi","Belle","Bolt","Mulan","Mowgli","Mickey","Silver","Simba","Stitch"},
{"Dumbo","Genie","Jiminy","Kuzko","Kida","Kenai","Tarzan","Tiana","Winnie"}
};
string str1;
int main ()
{
int n;
scanf("%d",&n);
int last = ,sum=;
while(n--)
{
cin>>str1; for(int i=; i<; i++)
{
for(int j=; j<; j++)
if(str1==str[i][j])
sum+=abs(i-last),last=i,j=,i=;
}
}
printf("%d\n",sum);
return ;
}
 

ural 2023 Donald is a postman(水)的更多相关文章

  1. Gym 100507L Donald is a postman (水题)

    Donald is a postman 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/L Description Donald ...

  2. URAL - 1917 Titan Ruins: Deadly Accuracy(水题)

    水题一个,代码挫了一下: 题意不好理解. 你去一个洞窟内探险,洞窟内有许多宝石,但都有魔法守护,你需要用魔法将它们打下来. 每个宝石都有自己的防御等级,当你的魔法超过它的防御等级时它就会被你打下来. ...

  3. ural 2012 About Grisha N.(水)

    2012. About Grisha N. Time limit: 1.0 secondMemory limit: 64 MB Grisha N. told his two teammates tha ...

  4. DFS水题 URAL 1152 False Mirrors

    题目传送门 /* 题意:一个圈,每个点有怪兽,每一次射击能消灭它左右和自己,剩余的每只怪兽攻击 搜索水题:sum记录剩余的攻击总和,tot记录承受的伤害,当伤害超过ans时,结束,算是剪枝吧 回溯写挫 ...

  5. URAL 2056 Scholarship 水题

    ScholarshipTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.a ...

  6. URAL 1136 Parliament 二叉树水题 BST后序遍历建树

    二叉树水题,特别是昨天刚做完二叉树用中序后序建树,现在来做这个很快的. 跟昨天那题差不多,BST后序遍历的特型,找到最后那个数就是根,向前找,比它小的那块就是他的左儿子,比它大的那块就是右儿子,然后递 ...

  7. ural 2032 Conspiracy Theory and Rebranding (数学水题)

    ural 2032  Conspiracy Theory and Rebranding 链接:http://acm.timus.ru/problem.aspx?space=1&num=2032 ...

  8. URAL 1001 Reverse Root(水题?)

    The problem is so easy, that the authors were lazy to write a statement for it! Input The input stre ...

  9. URAL 2066 Simple Expression (水题,暴力)

    题意:给定三个数,让你放上+-*三种符号,使得他们的值最小. 析:没什么好说的,全算一下就好.肯定用不到加,因为是非负数. 代码如下: #pragma comment(linker, "/S ...

随机推荐

  1. (4.8)SQL Server DAC——专用管理员连接

    SQL Server DAC——专用管理员连接 默认情况下,只有本地可以使用DAC连接,但也可以开启远程DAC sp_configure ; go reconfigure with override; ...

  2. mysql执行计划图

  3. POSIX相关概念

    POSIX 表示可移植操作系统接口(Portable Operating System Interface ,缩写为 POSIX),POSIX标准定义了操作系统应该为应用程序提供的接口标准,是IEEE ...

  4. 【Network】DDoS攻击防御

    DDoS(Distributed Denial of Service,分布式拒绝服务)攻击的主要目的是让指定目标无法提供正常服务,甚至从互联网上消失,是目前最强大,最难防御的攻击之一. 按照发起的方式 ...

  5. Simple Tips for Collection in Python

    I believe that the following Python code is really not hard to understand. But I think we should use ...

  6. mysql之视图,触发器,事务等

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...

  7. 曾经遇到的坑------href="#"和href="javascript:void(0);"、href="javascript:;"

    这个是为了 在点击此链接后回到页首,如果你写href="#"那么点击后会回到页首,这样影响操作. <a href="javascript:void 0" ...

  8. docker-compose no such image

    是由于docker-compose旧缓存的问题,执行docker-compose down即可,再重新up

  9. pyhton3 time模块

    来自:菜鸟教程 Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见的功能. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时间间隔是以秒为 ...

  10. HBase基本知识介绍及典型案例分析

    本次分享的内容主要分为以下五点: HBase基本知识: HBase读写流程: RowKey设计要点: HBase生态介绍: HBase典型案例分析. 首先我们简单介绍一下 HBase 是什么. HBa ...