Sicily.1035. DNA matching(字符串匹配)
来源:互联网 发布:pcb板设计软件 编辑:程序博客网 时间:2024/05/29 13:49
/*1035. DNA matching(字符串匹配) 大意:给出一系列的DNA单链,找出能够匹配成完整的DNA双链的最多对数 注意:每条单链只能使用一次 思路:依次往下扫描,找到匹配的两条都置为"0" */#include <iostream>#include <stdlib.h>#include <string>using namespace std;//从上往下扫描,对于匹配的串都设为“0”,避免重复扫描 int main(){ int T; int n; cin >> T; for(int i=1; i<=T; i++) { string a[100]; cin >> n; for(int k=0; k < n; k++) { cin >> a[k]; } int matchNum = 0; for(int k=0; k < n-1; k++) { for(int m=k+1; m <n; m++) { if(a[k] != "0" && a[k].length() == a[m].length()) { bool match = true; for(int j=0; j < a[m].length(); j++) { if(a[k][j] == 'A' && a[m][j] == 'T') continue; if(a[k][j] == 'T' && a[m][j] == 'A') continue; if(a[k][j] == 'C' && a[m][j] == 'G') continue; if(a[k][j] == 'G' && a[m][j] == 'C') continue; match = false; } if(match == true) { a[k] = "0"; a[m] = "0"; matchNum++; } } } } cout << matchNum << endl; } system("pause"); return 0;}