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
  1. 4
  2. Aurora
  3. Tiana
  4. Ariel
  5. Mulan
  1. 5
Problem Author: Alex Samsonov
Problem Source: NEERC 2014, Eastern subregional contest
 
 
 
 
 
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string str[][]= {{"Alice","Ariel","Aurora","Phil","Peter","Olaf","Phoebus","Ralph","Robin"},
  5. {"Bambi","Belle","Bolt","Mulan","Mowgli","Mickey","Silver","Simba","Stitch"},
  6. {"Dumbo","Genie","Jiminy","Kuzko","Kida","Kenai","Tarzan","Tiana","Winnie"}
  7. };
  8. string str1;
  9. int main ()
  10. {
  11. int n;
  12. scanf("%d",&n);
  13. int last = ,sum=;
  14. while(n--)
  15. {
  16. cin>>str1;
  17.  
  18. for(int i=; i<; i++)
  19. {
  20. for(int j=; j<; j++)
  21. if(str1==str[i][j])
  22. sum+=abs(i-last),last=i,j=,i=;
  23. }
  24. }
  25. printf("%d\n",sum);
  26. return ;
  27. }
 

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. Axure快捷键

    基本快捷键: 打开:Ctrl + O 新建:Ctrl + N 保存:Ctrl + S 退出:Alt + F4 打印:Ctrl + P 查找:Ctrl + F 替换:Ctrl + H 复制:Ctrl + ...

  2. vue-cli 搭建项目

    1.cnpm install -g vue-cli 2.vue -V(注意大写,查vue版本) 3.vue init webpack vue1(创建vue1目录) 4.cd vue1(定位到目录中) ...

  3. 【C语言】linux C写入本地文件

    //定义写入文件 FILE *pFile; //定义文件路径变量 ]; //变量赋值 sprintf(local_file,"/tmp/test.json"); //打开文件 pF ...

  4. centos中搭建nginx环境

    原文地址 安装PCRE 源码:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ cd /usr/local/src wget ftp://f ...

  5. android 对话框中的进度条 (ProgressDialog)

    from:http://byandby.iteye.com/blog/817214 显然要定义对话框进度条就要用ProgressDialog,首先我们需要创建ProgressDialog对象,当然这里 ...

  6. PAT 天梯赛 L1-038. 新世界 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-038 AC代码 #include <iostream> #include <cstdio&g ...

  7. 深入浅出Node.js(上)

    (一):什么是Node.js Node.js从2009年诞生至今,已经发展了两年有余,其成长的速度有目共睹.从在github的访问量超过Rails,到去年底Node.jsS创始人Ryan Dalh加盟 ...

  8. 使用SQL Server Management Studio 创建数据库备份作业

    --完整备份,每周一次USE MasterGOdeclare @str varchar(100)set @str='D:\Weldon\DBBACK\FullBak'+replace(replace( ...

  9. git上面创建个人简历-链接

    github创建个人在线简历: https://segmentfault.com/a/1190000006820290

  10. Windows10在待机状态时会卡屏的解决方案

    问题:Windows10在待机时,会出现卡屏(鼠标.键盘都无法操作,只能重启电脑),区别于平时我们看得比较多的花屏.蓝屏.黑屏. 原因:经过一段时间的待机,Windows10会进入到降电节能模式,由于 ...