UVA644

本文提供了一段C++代码用于比较字符串并判断一组字符串集中是否存在立即可读的编码集。通过比较字符串长度和字符匹配来确定是否可以立即解码。文章还附带了作者自述的问题和解决方案,涉及字符串处理和条件判断。

<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;
}

 

我就不明白为什么我写的会错。。。感觉都一样的阿。。

转载于:https://www.cnblogs.com/congluwen/p/3732860.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值