华为机试-DNA序列(HJ63)——纯C
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a?tpId=37&&tqId=21286&rp=1&ru=/ta/huawei&qru=/ta/huawei/question-ranking
纯C
#include <stdlib.h>
#include <stdio.h>
int main()
{
char *str = (char *)malloc(sizeof(char )*500);
while(gets(str))
{
int n;
scanf("%d", &n);
char *pstr = str;
int count, max=0;
for(int i=0; i<strlen(str); i++)
{
count=0;
for(int j=i; j<(i+n); j++)
{
if(str[j] == 'G' || str[j] == 'C')
{
count++;
if(count > max)
{
max=count;
pstr = str+i;
}
}
}
}
for(int i=0; i<n; i++)
{
printf("%c", *(pstr+i));
}
printf("\n");
}
free(str);
return 0;
}
查看12道真题和解析
