标签:
DNA碱基配对,只需要注意配对过的DNA单链不能再配对了,然后就直接按题意做就行了!
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 char s[105][105]; 8 bool used[105]; 9 10 bool is_pair(char s1[], char s2[]) 11 { 12 int len = strlen(s1); 13 for(int i=0; i<len; i++) 14 { 15 if(s1[i] == ‘A‘ && s2[i] != ‘T‘) 16 return 0; 17 if(s1[i] == ‘T‘ && s2[i] != ‘A‘) 18 return 0; 19 if(s1[i] == ‘C‘ && s2[i] != ‘G‘) 20 return 0; 21 if(s1[i] == ‘G‘ && s2[i] != ‘C‘) 22 return 0; 23 } 24 return 1; 25 } 26 27 int main() 28 { 29 int t; 30 scanf("%d", &t); 31 while(t--) 32 { 33 memset(used, 0, sizeof(used)); 34 int count=0; 35 int n; 36 scanf("%d", &n); 37 for(int i=0; i<n; i++) 38 scanf("%s", s[i]); 39 for(int i=0; i<n; i++) 40 for(int j=i+1; j<n; j++) 41 { 42 if(strlen(s[i]) != strlen(s[j])) 43 continue; 44 //for(int k=0; k<strlen(s[i]); k++) 45 if(is_pair(s[i], s[j]) && !used[i] && !used[j]) //注意匹配过的单链不能再用了 46 { 47 count++; 48 used[i]=1; 49 used[j]=1; 50 } 51 52 } 53 cout << count << endl; 54 } 55 return 0; 56 }
标签:
原文地址:http://www.cnblogs.com/dominjune/p/4355537.html