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 16:18:31 on Problem 3157
#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,k;
	k=0;
	char a[101];
	while(gets(a))
	{
	 k++;
	 printf("sample output #%d\n",k);
	 int l=strlen(a);
	 int he=0,da=0,g=0;
	 if(a[0]>='A'&&a[0]<='Z'||a[0]=='_')//开头大写或是—的 
	 {
	 	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++;
			if(a[i+1]=='_')
			{
			 printf("Error!\n");
			 g=1;
			 break;	
			}
		}
		if(a[i]=='_')
		{
			he++;	
	    	if(a[i+1]>='A'&&a[i+1]<='Z'||a[i+1]=='_')
	    	{
			 printf("Error!\n");
			 g=1;
			 break;	
			}
		}
	    if(a[i]<'A'||a[i]>'Z'&&a[i]!='_')
		{
		 printf("Error!\n");
		 g=1;
		 break;	
		}		
	 }
	 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