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

这样也不过!!!!!!!!!!!!!!

Posted by 457 at 2009-01-14 20:45:46 on Problem 3157
#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,k;
	k=0;
	char a[150];
	while(gets(a))
	{
	 k++;
	 printf("sample output #%d\n",k);
	 int l=strlen(a);
	 //printf("%d\n",l);
	 int he=0,da=0,g=0;
	 if(a[0]>='A'&&a[0]<='Z'||a[0]=='_')//开头大写或是'_'的 
	 {
	 	printf("Error!\n"); 
	 	continue;
	 }
	 else if(a[0]<'a'||a[0]>'z')
	 {
	  printf("Error!\n");
	  continue;		
	 }
	 if(a[l-1]=='_')//最后是'_'的 
	 {
	  printf("Error!\n");
	  continue;
	 }
	 for(i=0;i<l;i++)
	 {
		if(a[i]>='A'&&a[i]<='Z')
			da++;
		else if(a[i]=='_')
		{
			he++;	
	    	if(a[i+1]=='_')
	    	{
			 printf("Error!\n");
			 g=1;
			 break;	
			}
		}
		else if(a[i]<'a'||a[i]>'z')	    	
	 	{
		 printf("Error!\n");
		 g=1;
		 break;		
		}
	 }
	 if(da>0&&he>0) 
	 {
	  printf("Error!\n");
	  continue;		
	 }
	 if(g==1)	continue;
	 if(da>0)
	 for(i=0;i<l;i++)
	 {
	   if(a[i]>='A'&&a[i]<='Z')
	   {
	    printf("_");
	    a[i]=a[i]+32;
	   }
	  printf("%c",a[i]);	 		
	 }
	 else	if(he>0)
	 {
	  for(i=0;i<l;i++)
	  {
	    if(a[i]=='_')
		{
		 if(a[i+1]!='_')
		 a[i+1]=a[i+1]-32;
		 continue;	
		}
		printf("%c",a[i]);		
	  }		
	 }
	 else
	 	printf("%s",a);
	 printf("\n");
	}
}

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