POJ3080
来源:互联网 发布:淘宝海外直邮要身份证 编辑:程序博客网 时间:2024/05/17 04:27
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char str[20][65];
char st[65];
char s[65];
int n,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int i,j,k,l;
getchar();
bool flag = false;
int ans = 0;
for( i = 0; i<n; i++)
gets(str[i]);
int len = strlen(str[0]);
for( i = 0; i<len; i++)
{
for( k = i ; k < len; k++)
{
int num = 0;
//枚举子串
for( j = i; j <= k; j++)
st[num++] = str[0][j];
st[num] = '\0';
for( l = 1; l < n; l++)
if(strstr(str[l],st) == 0) break;//在2~n的字符串内寻找st,未找到则返回NULL(0)
if(ans < num && l == n)
{
ans = num;
strcpy(s,st);
}
else if(ans == num && l == n)
{
if(strcmp(s,st) > 0)
strcpy(s,st);
}
}
}
if(ans < 3)
cout<<"no significant commonalities"<<endl;
else
cout<<s<<endl;
}
}
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char str[20][65];
char st[65];
char s[65];
int n,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int i,j,k,l;
getchar();
bool flag = false;
int ans = 0;
for( i = 0; i<n; i++)
gets(str[i]);
int len = strlen(str[0]);
for( i = 0; i<len; i++)
{
for( k = i ; k < len; k++)
{
int num = 0;
//枚举子串
for( j = i; j <= k; j++)
st[num++] = str[0][j];
st[num] = '\0';
for( l = 1; l < n; l++)
if(strstr(str[l],st) == 0) break;//在2~n的字符串内寻找st,未找到则返回NULL(0)
if(ans < num && l == n)
{
ans = num;
strcpy(s,st);
}
else if(ans == num && l == n)
{
if(strcmp(s,st) > 0)
strcpy(s,st);
}
}
}
if(ans < 3)
cout<<"no significant commonalities"<<endl;
else
cout<<s<<endl;
}
}
0 0
- POJ3080
- poj3080
- poj3080
- poj3080
- poj3080
- poj3080
- poj3080
- POJ3080
- poj3080
- poj3080
- poj3080
- poj3080(kmp)
- poj3080 kmp
- poj3080 blue Jeans
- poj3080 kmp+枚举
- poj3080 Blue Jeans-------KMP
- Blue Jeans poj3080
- poj3080之KMP入门
- Java写人机猜拳游戏(可扩展其他游戏或其他参与者)
- 福建省队集训被虐记——DAY4
- 基于Go的D-Bus框架(一)
- FZU 2146 Easy Game
- Openfire 的安装和配置
- POJ3080
- activemq 消息队列 技术的介绍和原理
- C语言实现 hanio问题
- c++ const总结(转)
- 刘宇凡:苍井空靠粉丝经济卖内衣还能持续多久?
- POJ2993
- Tempter of the Bone
- POJ2485
- Android之shape与selector实现圆角