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

你是用C写的吗?

Posted by novicenet at 2009-11-04 19:22:49 on Problem 1575
In Reply To:一次AC,不为别的,只想问问大家我的代码可读性强不? Posted by:realkingiscoming at 2009-11-04 17:19:50
> #include <iostream>
> #include <string.h>
> using namespace std;
> 
> bool VorC(char c)
> {
> 	if((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))
> 		return true;
> 
> 	return false;
> }
> 
> bool Rule1(char s[])
> {
> 	int i;
> 
> 	for(i=0; i<strlen(s); i++)
> 		if(VorC(s[i]))
> 			return true;
> 	
> 	return false;
> }
> 
> bool Rule2(char s[])
> {
> 	int i;
> 
> 	if((strlen(s) == 1) || (strlen(s) == 2))
> 		return true;
> 
> 	for(i=0; i<strlen(s)-2; i++)
> 	{
> 		if(VorC(s[i]))//Is Vowel
> 		{
> 			if(VorC(s[i+1]))
> 				if(VorC(s[i+2]))
> 					return false;
> 		}
> 		else//Is Consonant
> 		{
> 			if(!VorC(s[i+1]))
> 				if(!VorC(s[i+2]))
> 					return false;
> 		}
> 	}
> 
> 	return true;
> }
> 
> bool Rule3(char s[])
> {
> 	int i;
> 	for(i=0; i<strlen(s)-1; i++)
> 		if((s[i] == s[i+1]) && (s[i] != 'e') && (s[i] != 'o'))
> 			return false;
> 
> 	return true;
> }
> 
> int main()
> {
> 	char s[21];
> 
> 	cin>>s;
> 
> 	while(strcmp(s, "end"))
> 	{
> 		if(Rule1(s))
> 			if(Rule2(s))
> 				if(Rule3(s))
> 				{
> 					cout<<"<"<<s<<"> is acceptable."<<endl;
> 					cin>>s;
> 					continue;
> 				}
> 
> 		cout<<"<"<<s<<"> is not acceptable."<<endl;
> 		cin>>s;
> 	}
> 
> 	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