标签:substr dna each font gen cstring positive ios tca
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 20404 | Accepted: 9043 |
Description
Input
Output
Sample Input
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities AGATAC CATCATCAT
本题利用C++的字符串暴力求解可以得到答案。
1 #include<cstring> 2 #include<iostream> 3 #include<string> 4 using namespace std; 5 string a[12]; 6 7 int main() 8 { 9 int T; 10 cin >> T; 11 while(T--){ 12 int n; 13 cin >> n; 14 for(int i=1;i<=n;i++){ 15 a[i].clear(); 16 cin >> a[i]; 17 } 18 string ans=""; 19 for(int i=3;i<=60;i++){ 20 for(int j=0;j<=60-i;j++){ 21 string temp=a[1].substr(j,i); 22 bool flag=true; 23 for(int k=2;k<=n;k++){ 24 if(a[k].find(temp)==string::npos){ 25 flag=false; 26 break; 27 } 28 } 29 if(flag&&temp.size()>ans.size()) ans=temp; 30 else if(flag&&temp.size()==ans.size()&&temp<ans) ans=temp; 31 } 32 } 33 if(ans=="") cout << "no significant commonalities" << endl; 34 else cout << ans << endl; 35 } 36 return 0; 37 }
substr(x,y)表示获取从x位开始长度为y的子串。
于是用获取得到的子串进行查找。即,find()。
标签:substr dna each font gen cstring positive ios tca
原文地址:https://www.cnblogs.com/ZQUACM-875180305/p/9286447.html