-
Notifications
You must be signed in to change notification settings - Fork 1
/
1035_DNA_matching.cpp
76 lines (72 loc) · 1.71 KB
/
1035_DNA_matching.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Problem#: 1035
// Submission#: 953795
// 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 <string>
#include <algorithm>
using namespace std;
string Dnastring[100];
bool stata[100];
bool cmp(string a,string b)
{
return (a > b);
}
bool match(string a,string b)
{
if(a.length() != b.length())return false;
for(int i = a.length() - 1;i >= 0;i --)
{
if(a[i] == 'T' && ! (b[i] == 'A'))return false;
if(a[i] == 'A' && ! (b[i] == 'T'))return false;
if(a[i] == 'G' && ! (b[i] == 'C'))return false;
if(a[i] == 'C' && ! (b[i] == 'G'))return false;
}
return true;
}
void judge()
{
int n;
cin >> n;
int count = 0;
for(int i = 0;i < n;i ++)
{
cin >> Dnastring[i];
stata[i] = false;
}
sort(Dnastring,Dnastring + n,cmp);
for(int i = 0;i < n;i ++)
{
if(stata[i] == true)
{
i++;
continue;
}
for(int j = i;j < n;j ++)
{
if(stata[j] == true)
{
j++;
continue;
}
else if(match(Dnastring[i],Dnastring[j]))
{
stata[i] = true;
stata[j] = true;
count ++;
break;
}
}
}
cout << count << endl;
}
int main()
{
int n;
cin >> n;
for(int i = 0;i < n;i ++)
{
judge();
}
}