题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
#include <stdio.h> #include <string.h> int main(){ char str[1002]; scanf("%s", str); int n; scanf("%d", &n); int len = strlen(str); char tmp[n], tmp_max[n]; float max = 0; for(int i = 0; i < len - n + 1; i++){ sprintf(tmp, "%.*s", n, str + i); int count = 0; for(int j = 0; j < n; j++){ if(tmp[j] == 'C' || tmp[j] == 'G'){ count++; } } if(max < (float)count / n){ max = (float)count / n; sprintf(tmp_max, "%s", tmp); } } printf("%s", tmp_max); return 0; }