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. django startapp报 maximum recursion depth exceeded

    报错截图如下: 解决办法:修改指定路径下的functools.py文件的def total_ordering(cls):方法: 原来的样子: convert = { '__lt__': [('__gt ...

  2. 查看hive的配置信息

    在启动hive时设置配置属性信息 $ bin/hive --hiveconf <property=value> 查看当前所有的配置信息 hive > set ; hive (db_h ...

  3. (3.2)mysqldump之备份单个表及脚本批量备份

    单库单表备份通用格式  mysqldump -uroot -p123456 test1 char_1>/opt/mysql_test1_char1.sql 分析:这里test1是库名,char_ ...

  4. 使用Kotlin开发Android应用(I):简介

    Kotlin是一门基于JVM的编程语言,它正成长为Android开发中用于替代Java语言的继承者.Java是世界上使用最多的编程语言之一,当其他编程语言为更加便于开发者使用而不断进化时,Java并没 ...

  5. MySQL的SQL MODE

    SQL MODE:定义mysqld对约束等的响应行为:    查看当前模式:        mysql> SHOW GLOBAL VARIABLES LIKE 'sql_mode';    修改 ...

  6. requirejs源码分析: define 方法

    define = function (name, deps, callback) {     var node, context; //Allow for anonymous modules     ...

  7. Ubuntu 16.04 php卸载

    1.卸载 apache2 sudo apt-get --purge remove apache2* sudo apt-get autoremove apache2 (--purge 是完全删除并且不保 ...

  8. 架构在APP和前端里的应用和演进

    架构设计相关的理念.技术.实践,比如存储高可用.微服务.异地多活等,都是后端系统才会涉及.事实上确实也是如此,通常情况下我们讲架构设计,主要聚焦在后端系统,但这并不意味着 App.前端就没有架构设计了 ...

  9. webbrowser控件——Windows下的开发利器

    首先说明,本人比较菜,做C++没多长时间. 刚开始用MFC写程序时,连个基本的字体都不会变(颜色.大小等), 索性干脆就啥也不改了,直接默认,界面就那样了,老子不管了. 心想这C++做个界面咋就那么麻 ...

  10. 利用 :before 特性实现图片按比例显示

    好吧,想不到自称布局小沙弥的我会被图片按比例显示给尴尬到. 设计师跟我说,这里的图要按 750x330 的,好吧,但这图是屏宽呀,屏幕宽度会变化的,那高度也会不定咯, 要么裁图片(工作量大),要么给定 ...