Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

附代码纪念游过80,硬上呗

Posted by realkingiscoming at 2009-11-08 22:15:26 on Problem 3366
//poj 3366

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


#include <iostream>
using namespace std;

int i;
int l;
int n;
char irregular[30][25];
char plural[30][25];
char str[25];

bool is_consonant(char c)
{
	if((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))
		return false;
	
	return true;
}

int is_irregular(char * str)
{
	for(int i=0; i<l; i++)
		if(strcmp(str, irregular[i]) == 0)
			return i;

	return -1;
}

int main()
{
	cin>>l>>n;

	for(i=0; i<l; i++)
		cin>>irregular[i]>>plural[i];

	for(i=0; i<n; i++)
	{
		cin>>str;

		int index = is_irregular(str);
		if(index != -1)
			cout<<plural[index]<<endl;
		else if(is_consonant(str[strlen(str)-2]) && (str[strlen(str)-1] == 'y'))
		{
			int pre_len = strlen(str);

			str[pre_len-1] = 'i';
			str[pre_len] = 'e';
			str[pre_len+1] = 's';
			str[pre_len+2] = '\0';

			cout<<str<<endl;
		}
		else if(	(str[strlen(str)-1] == 'o') || 
					(str[strlen(str)-1] == 's') || 
					(str[strlen(str)-1] == 'x') || 
					((str[strlen(str)-1] == 'h') && (str[strlen(str)-2] == 'c')) ||
					((str[strlen(str)-1] == 'h') && (str[strlen(str)-2] == 's')))
		{
			int pre_len = strlen(str);

			str[pre_len] = 'e';
			str[pre_len+1] = 's';
			str[pre_len+2] = '\0';

			cout<<str<<endl;
		}
		else
		{
			int pre_len = strlen(str);

			str[pre_len] = 's';
			str[pre_len+1] = '\0';

			cout<<str<<endl;
		}
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator