<code>
#include<stdio.h>
#include<string.h>
char
str[100][100];
int com(int t,int x)
{
int n,m,i;
n=strlen(str[t]);
m=strlen(str[x]);
n=(n>m)?m:n;
for(i=0;i<n;i++)
{
if(str[t][i]!=str[x][i])
return 1;
}
return 0;
}
int main()
{
int
t,leap,i;
t=0;
leap=0;
int cas=0;
while(gets(str[t])!=NULL)
{
if(str[t][0]==‘9‘)
{
cas++;
if(leap)
printf("Set %d is
not immediately decodable\n",cas);
else
printf("Set %d is immediately decodable\n",cas);
t=0;
leap=0;
continue;
}
for(i=0;i<t;i++)
{
if(com(t,i)==0)
{
leap=1;
}
}
t++;
}
return 0;
}
</code>
//我写的
#include <iostream>
#include <string>
using namespace
std;
int main()
{
string code[100];
int t = 0;
int
cas = 0;
bool Is = true;
while(cin >> code[t])
{
if(code[t] == "9")
{
++cas;
if(Is)
cout << "Set " << cas << " is
immediately decodable" << endl;
else
cout << "Set " << cas << " is not immediately decodable"
<< endl;
Is = true;
t = 0;
continue;
}
for(int i = 0 ; i < t; i++)
{
//cout << code[t].find(code[i]) << endl;
if(code[t].find(code[i]) == 0)
{
Is
=false;
break;
}
}
t++;
}
return 0;
}
我就不明白为什么我写的会错。。。感觉都一样的阿。。
原文地址:http://www.cnblogs.com/congluwen/p/3732860.html