Description
Input
Output
Sample Input
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities AGATAC CATCATCAT
#include<iostream> #include <string> using namespace std; string a[1000]; int main() {int t,i,n,j,k; cin>>t; while(t--) {cin>>n; string b=""; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<=a[0].size();i++) { for(j=0;j<=a[0].size();j++) {bool p=0; string temp = a[0].substr(j, i); for(k=1;k<n;k++) {if (a[k].find(temp) == string::npos) {p=1; break;} } if(p==0) if(temp.length()>b.length())b=temp; else if(temp.length()==b.length()&&b>temp)b=temp; } } if(b.size()<3) printf("no significant commonalities\n"); else cout<<b<<endl; } return 0;}
原文:http://www.cnblogs.com/cynchanpin/p/6971459.html