[Sicily online] 1035. DNA matching

Source: Internet
Author: User
/* Use map. Note that duplicate constraintstime limit: 1 secs, memory limit: 32 mbdescriptiondna (deoxyribonucleic acid) is founded in every living creature as the storage medium for genetic information. it is comprised of subunits called Nucleus otides that are strung together into polymer chains. DNA polymer chains are more commonly called DNA strands. there are four kinds of nucleus otides in DNA, distinguished by the Chem Ical 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 to 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, Su Ch 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 o F 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 us Ed 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 your other assignments to finish, and you shoshould not waste too much time here, so, hurry up please! Inputinput may contain in 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. outpu Tfor 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 input23atcgtagctagg2aattattasample output10 */# include <iostream> # include <stdio. h> # include <cmath> # include <iomanip> # include <map> # include <vector> # include <string> # include <algorithm> # include <sstream> # include <stack> using namespace s TD; string getop (string X) {for (string: size_type I = 0; I <X. size (); I ++) {If (X [I] = 'A') x [I] = 'T '; else if (X [I] = 'G') x [I] = 'C'; else if (X [I] = 'C ') X [I] = 'G'; else if (X [I] = 'T') x [I] = 'a';} // end forreturn X ;} int main () {int N; CIN> N; For (INT xx = 0; XX <n; XX ++) {int m; CIN> m; int COUNT = 0; Map <string, int> data; for (int yy = 0; YY <m; YY ++) {string TMP; CIN> TMP; data [TMP] ++;} // end for yymap <string, int >:: iterator ite; For (ITE = data. beg In (); ite! = Data. end ();) {string opstr = getop (ITE-> first); Map <string, int >:: iterator itetmp; itetmp = data. find (opstr); If (itetmp! = Data. end () {count ++; If (-- itetmp-> second) = 0) data. erase (itetmp); If (-- ite-> second) = 0) data. erase (ITE);} // end ifelse {data. erase (data. begin ();} // end elseif (data. begin () = data. end () break; ite = data. begin () ;}// end for itecout <count <Endl ;}// end for XX}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.