首页 > ACM题库 > HDU-杭电 > HDU 1804 Deli Deli-模拟-[解题报告] C++
2013
12-23

HDU 1804 Deli Deli-模拟-[解题报告] C++

Deli Deli

问题描述 :

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.

输入:

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’).

输出:

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

样例输入:

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

样例输出:

rice
lobsters
spaghetti
strawberries
octopi
peaches
turkeys

题目链接:Click
here~~

水水的字符串处理。主要练习下map的用法。

不过这道题,让我一下就想起了初中刚学英语的时候,各种怀念啊。

题意:

输出单词的复数形式。有些是特殊变换的,它事先给你。其他的按照规则变换。

解题思路:

特殊变换的用map存,其他的直接模拟。

#include <map>
#include <string>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
bool fuyin(char c)
{
	return c-'a' && c-'e' && c-'i' && c-'o' && c-'u';
}
bool ES(char d,char c)
{
	return c=='o' || c=='s' || c=='x' || (c=='h'&&(d=='c'||d=='s'));
}
int main()
{
	int n,m,l;
	char a[25],b[25];
	string A,B;
	map<string,string> M;
	map<string,string>::iterator it;
	while(~scanf("%d%d",&m,&n))
	{
		while(m--)
		{
			scanf("%s%s",a,b);
			M[a] = b;
		}
		while(n--)
		{
			scanf("%s",a);
			it = M.find(a);
			if(it != M.end())
				cout<< (*it).second <<endl;
			else
			{
				l = strlen(a);
				if(fuyin(a[l-2]) && a[l-1]=='y')
				{
					a[l-1]='i';
					strcat(a,"es");
				}
				else if(ES(a[l-2],a[l-1]))
					strcat(a,"es");
				else
					strcat(a,"s");
				puts(a);
			}
		}
		M.clear();
	}
	return 0;
}

解题报告转自:http://blog.csdn.net/dgq8211/article/details/7589397


  1. #include <stdio.h>
    int main(void)
    {
    int arr[] = {10,20,30,40,50,60};
    int *p=arr;
    printf("%d,%d,",*p++,*++p);
    printf("%d,%d,%d",*p,*p++,*++p);
    return 0;
    }

    为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下?