这题用strstr相对来说思路清晰,代码也清晰:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<set>
using namespace std;
int main()
{
char s[20];
int cas=0;
int len=0;
while(gets(s))
{
char ss[10][20];
if(s[0]=='9')
{
cas++;
int flag=0;
for(int i=0;i<len;i++)
{
for(int j=0;j<len;j++)
{
if(i!=j&&strstr(ss[j],ss[i])!=NULL&&strcmp(strstr(ss[j],ss[i]),ss[j])==0)
{
flag=1;
break;
}
}
if(flag==1)
break;
}
if(flag==1)
printf("Set %d is not immediately decodable\n",cas);
else
printf("Set %d is immediately decodable\n",cas);
len=0;
}
else
{
strcpy(ss[len++],s);
}
}
return 0;
}