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 atlas_of_rruucc at 2004-08-08 00:01:51 on Problem 1453
In Reply To:我实在找不出错了,哪位大大有时间帮我看看,Sample Input可以得到正确的答案 Posted by:windbells at 2004-08-07 23:28:35
> 是不是命令后的空格也要输出
> 所以"RESULT:"后至少有2个空格
> 
> 
> #include<stdio.h>
> #include<string.h>
> int main()
> {
> 	char commad[100],arry[10005],pre,tmp,clj[26];
> 	int i,size,brry[26],key,flag;
> 	for(i=0;i<26;i++)
> 	{
> 		clj[i]=i+'A';//值对应的字母
> 		brry[i]=i;//字母对应的值
> 	}
> 	while(scanf("%s",commad)!=EOF)
> 	{
> 		gets(arry);
> 		size=strlen(arry);pre='A';
> 		if(strcmp(commad,"ENCRYPT")==0)
> 		{
> 			for(i=0;i<size;i++)
> 			{
> 				if(arry[i]>='a'&&arry[i]<='z')
> 				{
> 					tmp=arry[i];
> 					arry[i]=clj[(brry[arry[i]-'a']-brry[pre-'A']+26)%26];
> 					pre=tmp-32;
> 					if(arry[i]>='A'&&arry[i]<='Z')
> 						arry[i]+=32;
> 				}
> 				else if(arry[i]>='A'&&arry[i]<='Z')
> 				{
> 					
> 					tmp=arry[i];
> 					arry[i]=clj[(brry[arry[i]-'A']-brry[pre-'A']+26)%26];
> 					pre=tmp;
> 					if(arry[i]>='a'&&arry[i]<='z')
> 						arry[i]-=32;
> 				}
> 				else pre='A';
> 			}
> 			printf("RESULT: %s\n",arry);
> 		}
> 		else if(strcmp(commad,"DECRYPT")==0)
> 		{
> 			for(i=0;i<size;i++)
> 			{
> 				if(arry[i]>='a'&&arry[i]<='z')
> 				{
> 					arry[i]=clj[(brry[pre-'A']+brry[arry[i]-'a'])%26];
> 					pre=arry[i];
> 					if(arry[i]>='A'&&arry[i]<='Z')
> 						arry[i]+=32;
> 				}
> 				else if(arry[i]>='A'&&arry[i]<='Z')
> 				{
> 					
> 					arry[i]=clj[(brry[pre-'A']+brry[arry[i]-'A'])%26];
> 					pre=arry[i];
> 					if(arry[i]>='a'&&arry[i]<='z')
> 						arry[i]-=32;
> 				}
> 				else pre='A';
> 			}
> 			printf("RESULT: %s\n",arry);
> 		}
> 		else if(strcmp(commad,"CIPHER")==0)
> 		{
> 			for(i=0;i<26;i++)
> 				brry[i]=26;
> 			key=0;flag=1;
> 			for(i=0;i<size;i++)
> 			{
> 				if(arry[i]>='a'&&arry[i]<='z')
> 				{
> 					clj[key++]=arry[i]-32;
> 					if(brry[arry[i]-'a']!=26)
> 					{
> 						flag=0;
> 						break;
> 					}
> 					else brry[arry[i]-'a']=key-1;
> 				}
> 				else if(arry[i]>='A'&&arry[i]<='Z')
> 				{					
> 					clj[key++]=arry[i];
> 					if(brry[arry[i]-'A']!=26)
> 					{
> 						flag=0;
> 						break;
> 					}
> 					else brry[arry[i]-'A']=key-1;
> 				}
> 				if(flag==0)
> 					break;
> 			}
> 			if(key!=26)
> 				flag=0;
> 			if(flag==0)
> 			{
> 				for(i=0;i<26;i++)
> 				{
> 					clj[i]=i+'A';
> 					brry[i]=i;
> 				}
> 				printf("Bad cipher.  Using default.\n");
> 			}
> 			else 
> 			{
> 				printf("Good cipher.  Using ");
> 				for(i=0;i<26;i++)
> 					printf("%c",clj[i]);
> 				printf(".\n");
> 			}
> 		}
> 		else printf("Command not understood.\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