| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
其实思路很简单,输入部分就是首先判断输入的字符串是不是为EOF。然后里面在判断是不是为9思路就是 ,输入字符串后然后依次全排列,一个一个比较,长度大于被比较的数时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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator