Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我们村里 通网了

Posted by 2012201208 at 2017-11-29 14:09:49 on Problem 1007
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, m;
struct solver{
    int cnt, value;
    char str[55];
    void input(int i){
        this->cnt = i;
        scanf("%s", str);
        build();
    }
    // 逆序数
    void build() {
        int A , T , C , G;
        A = T = C = G = 0;
        int ans = 0;
        for(int i = 0 ; i < n ; i++) {
            if (str[i] == 'A') A ++ , ans += C + G + T;
            if (str[i] == 'C') C ++ , ans += G + T;
            if (str[i] == 'G') G ++ , ans += T;
            if (str[i] == 'T') T ++;
        }
        value = ans;
    }
    void output(){
        printf("%s\n", str);
    }
    bool operator < (const solver & rht) const {
        if(this->value == rht.value) return this->cnt < rht.cnt;
        return this->value < rht.value;
    }
};
solver key[110];
int main() {
    while(~scanf("%d%d", &n, &m)) {
        for(int i = 0 ;i < m ; i++) key[i].input(i);
        sort(key, key + m);
        for(int i = 0 ;i < m ; i++) key[i].output();
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator