一道c/c++ 程序题

/*ProblemDescriptionYouaregivenanumberofcase-sensitivestringsofalphabeticcharacters,f... /*Problem Description
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X,
or its inverse can be found as a substring of any of the given strings.

Input
The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases,
followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100),
the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100.
There is no extra white space before and after a string.

Output
There should be one line per test case containing the length of the largest string found.

Sample Input
2
3
ABCD
BCDFF
BRCD
2
rose
orchid
Sample Output
2
2*/
展开
 我来答
匿名用户
2013-12-18
展开全部
#include<iostream>
#include<cstring>
using namespace std;
int t,n;
char s[101][101];
int maxn(char s2[])
{
int l1=strlen(s2),l2=strlen(s2);
char k1[101],k2[101];
int i,j;
bool found;
while(l1>0)
{
for(i=0;i<=l2-l1;i++)
{
strncpy(k1,s2+i,l1);
for(j=0;j<l1;j++)
k2[j]=k1[l1-1-j];
k1[l1]=k2[l1]='\0';
found=true;
for(j=0;j<n;j++)
{
if(strstr(s[j],k1)==NULL&&strstr(s[j],k2)==NULL)
{
found=false;
break;
}
}
if(found)
{
//cout<<k1<<endl;
return l1;
}
}
l1--;
}
return 0;
}
int main()
{
cin>>t;
while(t--)
{
cin>>n;
int i,j=101;
char s1[101];
for(i=0;i<n;i++)
cin>>s[i];
for(i=0;i<n;i++)
if(strlen(s[i])<j)
{
strcpy(s1,s[i]);
j=strlen(s[i]);
}
cout<<int(maxn(s1))<<endl;
}
return 0;
} 试试吧,重装系统还没来得及下软件、
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
意法半导体(中国)投资有限公司
2023-06-12 广告
char seg7[10]={0xc0,0xf9,0xa4,0xb0,0x9,0x92,0x82,0xf8,0x80} sbit w1=b2^0; sbit w2=b2^1; sbit k1=b3^0; /=1表示键盘按下 char cou... 点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
匿名用户
2013-12-18
展开全部
题目网站告诉我
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式