• sicily 1035. DNA matching


     1 #include<iostream>
     2 #include<cstdio>
     3 #include<string>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 bool cmp(string a, string b);
     8 bool match(string a, string b);
     9 
    10 
    11 int main(void) {
    12     int testSize, couple;
    13     string str[101];
    14     int len[101];
    15     bool used[101];
    16 
    17     // for each test case: (t<=20)
    18     cin >> testSize;
    19     while(testSize--) {
    20         // scan and store n strings(n <= 100)
    21         cin >> couple;
    22         for (int i = 0; i < couple; ++i) {
    23             cin >> str[i];
    24         }
    25 
    26         // sort by length
    27         sort(str, str + couple, cmp);
    28         //sort(<#_RandomAccessIterator __first#>, <#_RandomAccessIterator __last#>, <#_Compare __comp#>)
    29 
    30         for (int i = 0; i < couple; ++i) {
    31             // store length
    32             len[i] = str[i].size();
    33             // init used
    34             used[i] = false;
    35         }
    36 
    37         int count = 0;
    38 
    39         for (int i = 0; i < couple; ++i) {
    40             if (!used[i]) {
    41                 for (int j = i + 1; j < couple && len[j] == len[i]; ++j) {
    42                     if (match(str[i], str[j]) && !used[j]) {
    43                         count++;
    44                         used[i] = used[j] = true;
    45                         break;
    46                     }
    47                 }
    48             }
    49         }
    50 
    51         cout << count << '
    ';
    52     }
    53 
    54     return 0;
    55 }
    56 
    57 bool cmp(string a,string b)
    58 {
    59     return a.size() > b.size();
    60 }
    61 bool match(string a,string b){
    62     int len = a.size();
    63     for (int i = 0; i<len; i++) {
    64         if (a[i] == 'A' && b[i] != 'T')
    65             return false;
    66         if (a[i] == 'T' && b[i] != 'A')
    67             return false;
    68         if (a[i] == 'C' && b[i] != 'G')
    69             return false;
    70         if (a[i] == 'G' && b[i] != 'C')
    71             return false;
    72     }
    73     return true;
    74 }
  • 相关阅读:
    均值回归理论,均值回归法则是指万物最终都将回归于其长期的均值
    文本框仅允许输入大于0的正整数
    Angularjs接收服务端的布尔值
    Ajax POST单个对象或多个对象至API
    ASP.NET MVC程序重构
    查询数据库创建时间
    查询MS SQL的版本号
    获取Data和Log默认路径
    快速查找对象
    表关联使用INNER JOIN实现更新功能
  • 原文地址:https://www.cnblogs.com/zhousysu/p/5483668.html
Copyright © 2020-2023  润新知