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

关于pro3157,我实在调试不出来了,discuss上面的所有类型的数据都试过了……下面是程序(带注释)救我

Posted by TOTAL at 2007-02-07 21:52:51
#include<iostream>
#include<string.h>

char ou[210],in[210],out=0;

void java_to_c()//把java转为C
{
	int i=0;
	while (i<strlen(in))
	{
		if (64<in[i] && in[i]<91) //发现大写就改成c形式
		{
			ou[out]='_';
			out++;
			ou[out]=in[i]+32;
			out++;
		}else 
		{
			ou[out]=in[i];
			out++;
		}
		i++;
	}
}

void c_to_java()//把C转为java
{
	int i=0;
	while (i<strlen(in))
	{
		if (in[i]=='_')
		{
			i++;
			ou[out]=in[i]-32;
			out++;			
		}else
		{
			ou[out]=in[i];
			out++;
		}
		i++;
	}
}

bool debug_c(char c[210])//判断得到的C 标示符 是否合法
{
	int head=0;
	
	for (head=0;head<strlen(c);head++)
	{
		if (!((96<c[head] && c[head]<123) || c[head]=='_'))
		{
			return false;
		}
		if (c[head]=='_' && c[head+1]=='_')	return false;
	}
	return true;
}

int main()
{
	scanf("%s",in);
	
	
//排出3种常见的错误
	if (in[0]=='_' ||
		in[strlen(in)-1]=='_' ||
		(64<in[0] && in[0]<91))
	{
		printf("Error!\n");
		return 0;
	}


	int i,now=1;
//now是判断输入是java还是C++,0java:1C++


	
	for (i=0;i<strlen(in);i++)
		if (64<in[i] && in[i]<91)
		{
			now=0;
			break;
		}
	
	switch (now)
	{
		case 0: 
			{
				for (i=0;i<strlen(in);i++)
					if (in[i]=='_')
					{
						printf("Error!\n");						
						return 0;
					}
				java_to_c();
				
				if (!debug_c(ou)) printf("Error!\n");
				else printf("%s\n",ou);
				break;	
			}
		case 1:
			{
				if (debug_c(in))
				{
					c_to_java();
					printf("%s\n",ou);
				}
				else printf("Error!\n");
			}
	}

	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