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 whosyourdaddy at 2007-01-06 04:36:23 on Problem 3157
#include <stdio.h>
#include <string.h>


void main()
{
         char in[202];
	int i;
	char tmp1[200],tmp2[200];
	scanf("%s", in);
	{
		bool can=true;
		bool c=false;
		bool java=false;
		if(in[0]<='Z' || in[0]=='_'){//大写开头或者'_'开头
			can=false;
		}
		for(i=1;in[i];i++){
			if(in[i]<='Z'){
				if(c==true){//如果是c++的名字,出现大写就错
					can=false;
					break;
				}
				else{
					java=true;//是java型,往中间加一个'_',并变成小写
					char tmp3=in[i]+6+26;
					in[i]=0;
					strcpy(tmp1,in);
					in[i]=tmp3;
					strcpy(tmp2,&in[i]);
					in[0]=0;
					strcat(in,tmp1);
					strcat(in,"_");
					strcat(in,tmp2);
				}
			}
			else if(in[i]=='_'){
				if(java==true){//如果已经是java就错
					can=false;
					break;
				}
				else{
					if(in[i+1]==0 || in[i+1]<='Z' || in[i+1]=='_'){//如果以'_'结尾,或者后面还是'_',或者不是小写,就错
						can=false;
						break;
					}
					else{
						c=true;//去掉中间的'_',换成大写
						in[i]=0;
						strcpy(tmp1,in);
						in[i+1]-=6+26;
						strcpy(tmp2,&in[i+1]);
						in[0]=0;
						strcat(in,tmp1);
						strcat(in,tmp2);
						i++;
					}
				}
			}
		}
		if(can==false)
			printf("Error!\n");
		else
			printf("%s\n",in);
	}
}


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