zoukankan      html  css  js  c++  java
  • UVa 1368

    这是连续第8次1Y了,哈哈哈,不过,不过这题看起来挺吓人,读完才知道就是让球一个目标DNA序列,和每个所给序列最相近。不是从里面选,第一次就是这么理解的然后。。。。。是自己用A C G T中组合。如果有多解选字典序最小的。

    题目定位 : 字符串水题。 貌似有点贪心的意思。

    上Java代码 :

    import java.util.*;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner scan = new Scanner(System.in);
    	    int t = scan.nextInt();
    	    while(t-- > 0) {
    	    	int m = scan.nextInt();
    	    	int n = scan.nextInt();
    	    	StringBuilder sb = new StringBuilder();
    	    	String s;
    	    	DNA[] dna = new DNA[m + 1];
    	    	for(int i=0; i<m; i++) {
    	    		s = scan.next();
    	    		dna[i] = new DNA(s, 0);
    	    	}
    	    	int[] cnt = new int[4];
    	    	int dis = 0;
    	    	for(int j=0; j<n; j++) {
    	    		Arrays.fill(cnt, 0);
    	    		for(int i=0; i<m; i++) {
    	    			if(dna[i].str.charAt(j) == 'A') {
    	    				cnt[0] ++;
    	    			}
    	    			if(dna[i].str.charAt(j) == 'C') {
    	    				cnt[1] ++;
    	    			}
    	    			if(dna[i].str.charAt(j) == 'G') {
    	    				cnt[2] ++;
    	    			}
    	    			if(dna[i].str.charAt(j) == 'T') {
    	    				cnt[3] ++;
    	    			}
    	    		}
    	    		int max = cnt[0];
    	    		char ch = 'A';
    	    		for(int k=1; k<4; k++) {
    	    			if(cnt[k] > max) {
    	    				max = cnt[k];
    	    				if(k == 1) {
    	    					ch = 'C';
    	    				}
    	    				if(k == 2) {
    	    					ch = 'G';
    	    				}
    	    				if(k == 3) {
    	    					ch = 'T';
    	    				}
    	    			}
    	    		}
    	    		if(ch == 'A') {
    	    			dis += cnt[1] + cnt[2] + cnt[3];
    	    		}
    	    		if(ch == 'C') {
    	    			dis += cnt[0] + cnt[2] + cnt[3];
    	    		}
    	    		if(ch == 'G') {
    	    			dis += cnt[0] + cnt[1] + cnt[3];
    	    	    }
    	    		if(ch == 'T') {
    	    			dis += cnt[1] + cnt[2] + cnt[0];
    	    		}
    	    		sb.append(ch);
    	    		
    	    	}
    	    	System.out.println(sb);
    	    	System.out.println(dis);
    	    }
    	    
    
    	}
    
    }
    class DNA {
    	public String str;
    	public int cnt;
    	public DNA(String str, int cnt) {
    		this.str = new String(str);
    		this.cnt = cnt;
    	}
    }


     

  • 相关阅读:
    Lesson 2 :
    Session 1 : 笔记
    SpringBoot 3 : 单元测试和开发环境调试
    SpringBoot 2 : 网络配置
    MS leetcode 题目
    研二上末
    时不我待
    Do, I do!
    LeetCode 精选 TOP 面试题
    基于attractor landscape研究疾病发展及药物研发
  • 原文地址:https://www.cnblogs.com/wxisme/p/4363741.html
Copyright © 2011-2022 走看看