POJ之1007

题目链接:poj.org/problem?id=1007

/*

"DEABC",对于D有ABC三个按照字母顺序排列应该排在D前,此时在D后故,对D有逆序个数3,对于E同理逆序个数3,ABC均为正序,故整个字符串逆序程度为3
对于DNA序列input:
AACATGAAGG  
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
第一个3+5+2
第二个6*4+4*2+2*2
第三个7*3+5*2+3*2
第四个4+4+2+1
第五个3*1+6*1
第六个6+2+3+3+2+1
遇到A直接跳过,遇到C统计子串中的A,遇到G统计子串中的AC,遇到T统计子串中的ACG
故输出:
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA

*/

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
using namespace std;
int GetMaxString(int temp[],int n){
    int index = 0;
    for(int i=1; i< n; ++i){
        int minIndex = temp[index];
        if(temp[i] < minIndex){
            minIndex = temp[i];
            index = i;
        }
    }
    return index;
}
int main()
{
    int m,n;
    cin>>m;
    cin>>n;
    string input;
    vector<string> DNAString;
    int j =0;
    while(j<n){
        cin>>input;
        if((int)input.length() != m){
            cin>>input;
        }
        DNAString.push_back(input);
        j++;
    }
    int *calc = new int[n];
    for(int i=0; i < n; ++i){
        const char *temp = DNAString[i].data();
        int k = 0,sum = 0;
        for(;k < m-1;++k){
            if(temp[k]=='A'){
                continue;
            }
            else if(temp[k]=='C'){
                int c = k+1;
                if(c>=m) break;
                while(c<m){
                    if(temp[c]=='A'){
                        sum++;
                    }
                    c++;
                }
                continue;
            }else if(temp[k]=='G'){
                int g = k+1;
                if(g>=m) break;
                for(;g<m;g++){
                    if(temp[g]=='A' || temp[g]=='C'){
                        sum++;
                    }
                }
            }else{
                int t = k+1;
                if(t>=m) break;
                while(t<m){
                    if(temp[t]!='T'){
                        sum++;
                    }
                    t++;
                }
                continue;
            }
        }
        calc[i]=sum;
    }
    for(size_t i=0; i<DNAString.size(); ++i ){
        cout<<DNAString[GetMaxString(calc,n)]<<endl;
        calc[GetMaxString(calc,n)] = INT_MAX;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值