POJ3080Blue Jeans(暴力)

时间:2022-05-10 15:19:41

开始做字符串专题,地址

第一题水题,暴力就可以做

 #include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf (-((LL)1<<40))
#define lson k<<1, L, mid
#define rson k<<1|1, mid+1, R
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define FOPENIN(IN) freopen(IN, "r", stdin)
#define FOPENOUT(OUT) freopen(OUT, "w", stdout) template<class T> T CMP_MIN(T a, T b) { return a < b; }
template<class T> T CMP_MAX(T a, T b) { return a > b; }
template<class T> T MAX(T a, T b) { return a > b ? a : b; }
template<class T> T MIN(T a, T b) { return a < b ? a : b; }
template<class T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<class T> T LCM(T a, T b) { return a / GCD(a,b) * b; } //typedef __int64 LL;
typedef long long LL;
const int MAXN = ;
const int MAXM = ;
const double eps = 1e-; char str[][], ansStr[];
int T, N; int maxLen(char* s1, char* s2)
{
int ans = ;
for(int i=;s2[i];i++)
{
int len = ;
for(int j=;s1[j];j++)
{
if(s2[i+j] == s1[j]) len++;
else break;
}
ans = max(ans, len);
}
return ans;
} int main()
{
while(~scanf("%d", &T))while(T--)
{
mem0(str); mem0(ansStr);
scanf("%d%*c", &N);
for(int i=;i<N;i++) scanf("%s", str[i]);
int ans = ;
for(int i=;str[][i];i++)
{
int len = INF;
for(int j=;j<N;j++)
{
len = min( len, maxLen(&str[][i], str[j]) );
}
if(ans < len)
{
ans = len;
for(int j=i;j<i+ans;j++) ansStr[j-i] = str[][j];
ansStr[i+ans] = ;
}
else if(ans == len)
{
int ok = ;
for(int j=;j<ans;j++)
{
if(ok) ansStr[j] = str[][i+j];
else if(ansStr[j] != str[][i+j])
{
if(ansStr[j] < str[][i+j]) break;
else { ansStr[j] = str[][i+j]; ok = ; }
}
}
}
}
if(ans >= )
printf("%s\n", ansStr );
else printf("no significant commonalities\n");
}
return ;
}