HDOJ-1238 Substrings!
来源:互联网 发布:core java中文版下载 编辑:程序博客网 时间:2024/04/30 10:34
先对字符串进行排序,直接枚举长度最短的串的子串,再判断是否是其余字符串的公共子串即可。
#include <map>#include <string>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <memory.h>#include <algorithm>#include <vector>using namespace std;bool cmp(string a,string b){return a.size()<b.size();}int main(){int t;vector<string> buf;cin>>t;while(t--){int n;cin>>n;for(int i=0;i<n;i++){string tmp;cin>>tmp;buf.push_back(tmp);}sort(buf.begin(),buf.end(),cmp);string shortest=buf[0];int mmax=0;for(int len=shortest.size();len>=1;len--){for(string::size_type j=0;j<=shortest.size()-len;j++){string tmp=shortest.substr(j,len);string tmp1=tmp;reverse(tmp1.begin(),tmp1.end());int flag=0;for(vector<string>::size_type i=1;i!=buf.size();i++){string tmp2=buf[i];if(tmp2.find(tmp)>shortest.size()&&tmp2.find(tmp1)>shortest.size()){flag=1;break;}}if(!flag)mmax=len;}if(mmax)break;}cout<<mmax<<endl;buf.clear();}return 0;}
- hdoj 1238 Substrings
- HDOJ-1238 Substrings!
- 【KMP】 HDOJ 1238 Substrings
- hdoj 1238 Substrings
- HDOJ 1238:Substrings
- HDOJ 1238 Substrings
- HDOJ 1238 Substrings
- 【DP】 HDOJ 4455 Substrings
- HDOJ 1238:Substrings 寻找最长子序列 解题报告
- hdoj 1238 Substrings(字符串的子串)
- 1238 Substrings
- HDOJ 4455 Substrings 递推+树状数组
- HDOJ 题目4455 Substrings(DP)
- hdu-1238 Substrings
- 杭电1238 Substrings
- HDU 1238 Substrings
- HDU 1238 ( Substrings )
- Hdu 1238 Substrings
- PythonCardTricks
- opencv template match
- QuickSum
- Gtk and Win32 differences
- 【Android 开发】:Android五种布局的使用方法
- HDOJ-1238 Substrings!
- VIM 常用命令
- MapReduce:详解Shuffle过程
- 宏基4740g笔记本xp系统sata驱动安装
- 完美未来之星编程比赛 复赛第二场 发放激活码
- php连接关闭数据库mysql
- Android布局详解之二:LinearLayout
- sdut2152 Balloons
- opencv在windows系统中配置总结