Blue Jeans POJ 3080 (串)
来源:互联网 发布:淘宝名店 编辑:程序博客网 时间:2024/05/16 01:10
题意很简单,找最长且字典序最大的公共子串,并且长度不能小于3
方法是暴力,找出第一个字符串的所有子串,依次与后面的字符串匹配。
#include <stdio.h>#include <string.h>#include <algorithm>#include<iostream>using namespace std;char a[15][65];char temp[65];char answer[65];int len;int k;int Find;int cases,n;int main(){ cin>>cases; while(cases--) { Find=0; cin>>n; memset(answer,'\0',sizeof(answer)); for(int i=1; i<=n; ++i) scanf("%s",a[i]); for(int i=1; i<=60; ++i) { for(int j=0; j<=60-i; ++j) { int flag=1; len=0; for(k=j;; k++) { temp[len++] = a[1][k]; if(len == i) break; } temp[len]='\0'; //printf("%s\n",temp); for(k=2; k<=n; ++k) { if(!strstr(a[k],temp)) { flag=0; break; } } if(flag) { Find=1; if(strlen(answer)<strlen(temp)) strcpy(answer,temp); else if(strcmp(answer,temp)>0) strcpy(answer,temp); } } } if(!Find||strlen(answer)<3) { cout<<"no significant commonalities"<<endl; } else { printf("%s\n",answer); } } return 0;}
阅读全文
0 0
- POJ 3080 Blue Jeans(暴力 + 串)
- Blue Jeans POJ 3080 (串)
- poj 3080 Blue Jeans (串)
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- Poj 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- POJ 3080 Blue Jeans
- poj 3080 Blue Jeans
- poj 3080 Blue jeans
- centos7下yum安装mysql
- 学习总结-Thinking In Java Chapter 8 polymorphism
- 各种编程语言简介
- Python 3.X重新加载模块
- OSG数学基础:坐标系统
- Blue Jeans POJ 3080 (串)
- Git Basic
- 创建型模式前奏之简单工厂模式
- [机房练习赛7.11]graph
- 剑指offer--复杂链表的赋值
- Big O notation大零符合 入门讲解
- JAVA常量池之String类
- Linux下使用valgrind工具对C++编程检测内存泄露
- 浅谈Android MVP模式