1035. DNA matching
Description
DNA (deoxyribonucleic acid) is founded in every living creature as the storage medium for genetic information. It is comprised of subunits called Nucleus tides that are strung together into polymer chains. DNA polymer chains are
More commonly calledDNA strands.
There are four kinds of nucleus otides in DNA, distinguished by the chemical group, or base attached to it. the four bases are adenine, guanine, cytosine and thymine, abbreviated as A, G, C and T (these letters will be used
Refer to nucleus otides containing these bases ). single nucleus otides are linked together end-to-end to form DNA single strands via chemical reactions. for simplicity, we can use a string composed of letters A, T, C and G to denote a single strand, such as attcgac,
But we must also note that the sequence of nucleus otides in any strand has a natural orientation, so attcgac and cagctta can not be viewed as identical strands.
DNA does not usually exist in nature as free single strands, though. under appropriate conditions single strands will pair up and twist around each other, forming the famous double helix structure. This pairing occurs because
Of a mutual attraction, call hydrogen bonding, that exists between AS and Ts, and between GS and CS. Hence a/t and G/C are called complementary base pairs.
In the molecular biology experiments dealing with DNA, one important process is to match two complementary single strands, and make a DNA Double Strand. Here we give the constraint that two complementary single strands must have
Equal length, and the nucleus otides in the same position of the two single strands shoshould be complementary pairs. for example, attcgac and taagctg are complementary, but cagctta and taagctg are not, neither are attcgac and gtaagct.
As a biology research assistant, your boss has assigned you a job: given n single strands, find out the maximum number of double strands that cocould be made (of course each strand can be used at most once ). if n is small, of course
You can find the answer with the help of pen and paper, however, sometimes n cocould be quite large... Fortunately you are good at programming and there is a computer in front of you, so you can write a program to help yourself. But you must know that you have
Export other assignments to finish, and you shoshould not waste too much time here, so, hurry up please!
Input
Input may contain multiple test cases. the first line is a positive integer T (t <= 20), indicating the number of test cases followed. in each test case, the first line is a positive integer n (n <= 100), denoting the number of single strands below. and n lines
Follow, each line is a string comprised of four kinds of capital letters, A, T, C and G. The length of each string is no more than 100.
Output
For each test case, the output is one line containing a single integer, the maximum number of double strands that can be formed using those given single strands.
Sample Input
2
3
ATCG
TAGC
TAGG
2
AATT
ATTA
Sample output
1
0
Problem Source
Zsuacm team member
// Problem#: 1035// Submission#: 1175957// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <iostream>#include <map>#include <string>using namespace std;map<char,char>m;bool match(string a,string b){ if(a.length()!=b.length()) return false; else { for(int i=0;i<a.length();i++) { if(m[a[i]]!=b[i]) return false; } return true; }}int main(){ m['A']='T'; m['T']='A'; m['C']='G'; m['G']='C'; int t; cin>>t; while(t--) { int n; cin>>n; string str[100]; for(int k=0;k<n;k++) cin>>str[k]; int count=0; for(int i=0;i<n;i++) { if(str[i]!="liucong") { for(int j=i+1;j<n;j++) { if(str[j]!="liucong"&&match(str[j],str[i])) { count++; str[j]="liucong"; break; } } } } cout<<count<<endl; } return 0;}