Problem Description
Mrs. Deli is running the delicatessen store “Deli Deli”. Last year Mrs. Deli has decided to expand her business and build up an online store. She has hired a programmer who has implemented the online store.

Recently some of her new online customers complained about the electronic bills. The programmer had forgotten to use the plural form in case that an item is purchased multiple times. Unfortunaly the programmer of Mrs. Deli is on holiday and now it is your task to implement this feature for Mrs. Deli. Here is a description how to make the plural form:

  1. If the word is in the list of irregular words replace it with the given plural.
  2. Else if the word ends in a consonant followed by “y”, replace “y” with “ies”.
  3. Else if the word ends in “o”, “s”, “ch”, “sh” or “x”, append “es” to the word.
  4. Else append “s” to the word.

Input
The first line of the input file consists of two integers L and N (0 ≤ L ≤ 20, 1 ≤ N ≤ 100). The following L lines contain the description of the irregular words and their plural form. Each line consists of two words separated by a space character, where the first word is the singular, the second word the plural form of some irregular word. After the list of irregular words, the following N lines contain one word each, which you have to make plural. You may assume that each word consists of at most 20 lowercase letters from the english alphabet (‘a’ to ‘z’).

Output
Print N lines of output, where the ith line is the plural form of the ith input word.

Sample Input
3 7
rice rice
spaghetti spaghetti
octopus octopi
rice
lobster
spaghetti
strawberry
octopus
peach
turkey

Sample Output
rice
lobsters
spaghetti
strawberries
octopi
peaches
turkeys

思路:这道题就是一个模拟题,首先先定义一个map<string,string>mp的容器,再L行中字符串a,和字符串b,用map[ a ] = b 存起来。后面用到了map容器中的find函数,mp.find(a)
如果mp中存在按a索引的元素,则返回指向该元素的迭代器。如果不存在,则返回结束游标end()

#include<bits/stdc++.h>
using namespace std;
int main()
{map<string, string>mp;char a[100], b[100];int l, n;while (~scanf("%d %d%*c", &l, &n)){int i, j;for (i = 0; i < l; i++){scanf("%s %s", a, b);mp[a] = b;}for (i = 0; i < n; i++){scanf("%s", a);if (mp.find(a) != mp.end()){cout << mp[a] << endl;}else{if (a[strlen(a)-1] == 'y'&&a[strlen(a)-2]!='e'&&a[strlen(a) - 2] != 'o'&&a[strlen(a) - 2] != 'a'&&a[strlen(a) - 2] != 'i'&&a[strlen(a) - 2] != 'u'){a[strlen(a)-1] = 'i';cout << a << "es" << endl;}else if (a[strlen(a)-1] == 'o' || a[strlen(a)-1] == 's' || a[strlen(a)-1] == 'x' || ((a[strlen(a) - 2] == 'c' || a[strlen(a) - 2] == 's') && a[strlen(a)-1] == 'h')){cout << a << "es" << endl;}else{cout << a << "s" << endl;}}}}return 0;
}

Deli Deli(模拟,map容器)相关推荐

  1. Social Network(运用map容器)

    题目链接: Social Network (hard version) 题目: 你正在一个流行的社交网络中通过智能手机发送信息.你的智能手机最多可以显示k个最近与朋友的对话.最初,屏幕是空的(即显示的 ...

  2. [蓝桥杯2018初赛]次数差-模拟,map容器

    题目描述 x星球有26只球队,分别用a~z的26个字母代表.他们总是不停地比赛. 在某一赛段,哪个球队获胜了,就记录下代表它的字母,这样就形成一个长长的串. 国王总是询问:获胜次数最多的和获胜次数最少 ...

  3. HDOJ/HDU 1804 Deli Deli(英语单词复数形式~)

    Problem Description Mrs. Deli is running the delicatessen store "Deli Deli". Last year Mrs ...

  4. UVA11233 POJ3366 HDU1804 Deli Deli【水题】

    Deli Deli Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  5. java过滤map去除重复数据,javascript模拟map输出与去除重复项的方法

    本文实例讲述了javascript模拟map输出与去除重复项的方法.分享给大家供大家参考.具体方法如下: 1.Javascriptmap输出 function Map(){ // private va ...

  6. C++ 中 map 容器的内存释放机制及内存碎片管理

    C++ 中 map 容器的内存释放机制及内存碎片管理 C++ 中的容器很好用,比如 vector, map 等,可以动态扩容,自己管理内存,不用用户关心,但是在某些极端情况下,如果内存比较紧张的情况下 ...

  7. Map容器大小影响key的索引

    单元测试偶然发现的Map一个问题 Map<String,String> map1 = new HashMap<>();map1.put("aaa", &qu ...

  8. CSU 1113 Updating a Dictionary(map容器应用)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...

  9. C++中map容器的说明和使用技巧

    C++中map容器提供一个键值对容器,map与multimap差别仅仅在于multiple允许一个键对应多个值. 1   头文件 #include <map> 2   定义 map< ...

最新文章

  1. html简单响应式滚动条置顶
  2. servlet中response中文乱码
  3. 文件中的类都不能进行设计,因此未能为该文件显示设计器。设计器检查出文件中有以下类: FormMain --- 未能加载基类...
  4. 甲骨文全球大会——看SOA
  5. 利用多项式特征生成与递归特征消除解决特征组合与特征选择问题
  6. Qt修炼手册10_QTableWidget控件使用说明及实践
  7. 从零开始学Axure原型设计(高级篇)
  8. linux系统上手工建库步骤,Linux下Oracle手工建库过程
  9. selenium下打开Chrome报错解决
  10. Linux内核启动中驱动初始化过程
  11. 人工智能时代的危机_AI信任危机:如何前进
  12. Weblogic下载与安装
  13. 北大飞跃手册_【通知】关于转发吉林大学大学生飞跃社团2020年吉林大学飞跃手册预发布会即将召开!...
  14. vivado 2018 下载地址
  15. python 之 libtorrent库
  16. 在电脑上通过手机发短信
  17. 手动添加打印机的方法(hp laserjet p2055dn为例)
  18. Java导出excel中response.setHeader()参数设置
  19. linux md5sum 的用法
  20. 百瑞BARROT BR2262e蓝牙模块的使用

热门文章

  1. 预编译安装Aspera的linux版本到centos系统
  2. SAP有个项目管理平台秘密武器叫ARIS
  3. gcms基峰有什么用_干货!气相色谱仪常见故障及维护知识集锦
  4. matlab完成信源编码译码,matlab哈夫曼译码
  5. 511遇见易语言取字节集长度取字节集数据到字节集
  6. AB PLC连接AB 继电器方法
  7. C语言练习第4天---输出斐波那契数列(循环,数组,函数)
  8. HMAC哈希消息认证码
  9. jQuery Sizzle选择器
  10. IPv4的私有IP地址和IPv6的私有IP地址 分享