Rockethon 2014 A. Genetic Engineering

本文介绍了一种针对基因序列的算法挑战,旨在通过插入最少数量的核苷酸使蛋白质功能正常。文章提供了一个示例问题及其解决方案,展示了如何确保所有连续相同字符的子串长度为奇数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Genetic Engineering
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You will receive 3 points for solving this problem.

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.


解题报告:

此题为模拟,只要连续的字母为偶数就加一,输出总和即可。代码如下:

#include<stdio.h>
#include<string.h>
char s[200];
int main(){
    scanf("%s",s);
    char tmp;
    int sum,len1,len;
    sum=0;tmp=s[0];len=1;len1=strlen(s);
    for(int i=1;i<len1;i++){
        if(tmp==s[i])
            len++;
        else{
            if(len%2==0)
                sum++;
            len=1;
            tmp=s[i];
        }
    }
    if(len%2==0)
        sum++;
    printf("%d\n",sum);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值