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 Loonlie at 2007-05-26 11:07:42 on Problem 3157
#include "stdio.h"
#include "string.h"
int main()
{
    char chlwr(char ch);
    char chupr(char ch);
    bool isCapital(char ch);
    bool isAlphet(char ch);
	char str[100];
	char res[200];
	scanf("%s",str);
	int tag=0;
	int i,j;
	int java;
	java=0;
	for(i=0,j=0;i<strlen(str);i++)
    {
      if(isCapital(str[i])){
          if(i==0||tag==2||java==2)
          {
              printf("ERROR!\n");
              return 0;
          }
          res[j++]='_';
          res[j++]=chlwr(str[i]);
          tag=1;
          java=1;
          }  
      if(isAlphet(str[i])){
          if(tag==2)
          {
                    res[j++]=chupr(str[i]);
                    tag=0;
          }    
          else
                    res[j++]=str[i];
      } 
      if(str[i]=='_'){
          if(i==0||i==(strlen(str)-1)||java==1)
          {
              printf("ERROR!\n");
              return 0;
          }
          if(tag==1||tag==2)
          {
              printf("ERROR!\n");
              return 0;
          }
          tag=2;
          java=2;
          }
	}    
	 res[j]='\0';
	 printf("%s\n",res);
return 0;
}
char chlwr(char ch)
{
    return ch+32;
}
char chupr(char ch)
{
    return ch-32;
}
bool isCapital(char ch)
{
    if(ch>=65&&ch<90)
        return true;
    else 
        return false;
}
bool isAlphet(char ch)
{
    if(ch>=97&&ch<122)
        return true;
        else 
        return false;
}

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