zoukankan      html  css  js  c++  java
  • Rockethon 2014 A. Genetic Engineering

    Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'.

    Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length.

    Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein.

    Input

    The input consists of a single line, containing a string s of length n (1 ≤ n ≤ 100). Each character of s will be from the set {'A', 'T', 'G', 'C'}.

    This problem doesn't have subproblems. You will get 3 points for the correct submission.

    Output

    The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length.

    Sample test(s)
    input
    GTTAAAG
    output
    1
    input
    AACCAACCAAAAC
    output
    5
    Note

    In the first example, it is sufficient to insert a single nucleotide of any type between the two 'T's in the sequence to restore the functionality of the protein.

    题目意思:

    求一个字符串中同一字符连续出现次数为偶数的个数。

    思路:

    遍历一次字符串,找出同一字符连续出现次数为偶数的个数;

    注意:

    1.最后一个''要格外注意,就像T123TT那个题

    代码:

     1 #include<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     char a[101];
     9     //freopen("aa.txt","r",stdin);
    10     while(cin>>a)
    11     {
    12         int ans=0;
    13         int sum=1;
    14         for(int i=1;i<=strlen(a);i++)//注意等号
    15         {
    16             if(a[i]==''||a[i]!=a[i-1])
    17             {
    18                 if(sum%2==0)
    19                     ans++;
    20                 sum=1;
    21             }
    22             else if(a[i]==a[i-1])
    23             {
    24                sum++;
    25             }
    26         }
    27         cout<<ans<<endl;
    28     }
    29     return 0;
    30 }
    View Code
  • 相关阅读:
    N4-某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。
    N3-按链表值从尾到头的顺序返回一个ArrayList。
    N2-替换字符串空格
    innodb死锁1213
    innodb是行锁还是表锁
    docker是什么,docker干什么用
    innodb通过frm ibd还原数据,线上项目验证过
    机器性能预警系统(cpu,process,内存,硬盘监控)并钉钉机器人报警
    mysql++ query.more_results()为true时,query.store_next()就崩掉了
    yum install nload失败,提示No package nload available.Error: Nothing to do
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3553190.html
Copyright © 2011-2022 走看看