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

其实思路很简单,输入部分就是首先判断输入的字符串是不是为EOF。然后里面在判断是不是为9

Posted by chenjin1st at 2011-11-25 08:20:15 on Problem 1056
思路就是 ,输入字符串后然后依次全排列,一个一个比较,长度大于被比较的数时continue
然后就是在被比较的字符串的中取比较字符串等长度的字符(前部分的)做比较就行了。水在输入部分,害我WE一次
代码部分。没有写注释,
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 11
int main(){
	char str[N],**value,back[N];
	int i,j,n,len1,len2,flag,number=1;
	value=(char **)malloc(N*sizeof(char *));
	n=0;flag=1;
	while(scanf("%s",str)!=EOF){
		if(str[0]!='9'){
			value[n]=(char *)malloc(N*sizeof(char));
			strcpy(value[n++],str);
		}else{
			for(i=0;i<n;i++){
				len1=(int)strlen(value[i]);
				for(j=0;j<n;j++){
					len2=(int)strlen(value[j]);
					if(i==j||len1>len2)
						continue;
					strcpy(back,value[j]);
					back[len1]='\0';
					if(!strcmp(back,value[i])){
						flag=0;
						break;
					}
				}
				if(!flag)
					break;
			}
			if(flag)
				printf("Set %d is immediately decodable\n",number++);
			else
				printf("Set %d is not immediately decodable\n",number++);
			for(i=0;i<n;i++)
				free(value[i]);
			n=0;flag=1;
		}
	}
	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