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. ARKit如何将太阳系装进iPhone(二)
  2. docker 与tomcat整合
  3. 3D Computer Grapihcs Using OpenGL - 04 First Triangle
  4. uvalive5096(积分题)
  5. Nginx反向代理的系统优化
  6. 密码学系列之:feistel cipher
  7. Java静态方法与非静态方法的泛型
  8. 每天Leetcode 刷题 初级算法篇-数学问题-3的幂
  9. 【蓝桥杯】2019:最长子序列
  10. spring学习--基于注解方式创建对象AOP
  11. 前端架构设计的方法论
  12. 智慧校园安防平台应用解决方案
  13. python之花瓣美女下载
  14. MFC中动态检测串口热插拔的实现
  15. 微软力挺程序员硬刚996!
  16. emv交易流程介绍_(精)EMV流程介绍.ppt
  17. 墨门云文件加密系统有哪些功能特点?
  18. Linux != Windows( Linux 不是 Windows)
  19. 南京市城乡地籍信息一体化管理的几点思考
  20. html转pdf文件下载之最合理的方法支持中文

热门文章

  1. 蛙蛙推荐:从C#到C语言
  2. 什么是Windows NT
  3. 连续变量的全概率和贝叶斯公式_全概率公式和贝叶斯公式
  4. 炫酷的鼠标特效JS 原生代码
  5. 2019湖南省职业院校技能竞赛集训开班典礼
  6. AB PLC 报错Compact I/O end cap missing
  7. 2021年危险化学品经营单位安全管理人员最新解析及危险化学品经营单位安全管理人员试题及解析
  8. 多线程(进阶)——常见锁策略+CAS+Synchronized优化过程
  9. Python_编程特色
  10. 6.2.1mnist _eval