POJ1542

来源:互联网 发布:电信4g网络差 编辑:程序博客网 时间:2024/05/19 00:52

简单的字符串处理的题,问题描述比较啰嗦,前面都是在科普DNA和RNA转录的知识,后面输入输出才提到核心问题。


#include<stdio.h>#include<string.h>char map[65][4] = { "Phe","Phe", "Leu","Leu", "Ser","Ser", "Ser","Ser", "Tyr","Tyr", "","", "Cys","Cys", "","Trp","Leu","Leu", "Leu","Leu", "Pro","Pro", "Pro","Pro", "His","His", "Gln","Gln", "Arg","Arg", "Arg","Arg", "Ile" ,"Ile", "Ile","Met", "Thr","Thr", "Thr","Thr", "Asn","Asn", "Lys","Lys", "Ser","Ser", "Arg","Arg","Val","Val", "Val","Val", "Ala","Ala", "Ala","Ala", "Asp","Asp", "Glu","Glu", "Gly","Gly", "Gly","Gly", };char s[256] = {}, sv[256] = {}, rs[256] = {}, rsv[256] = {};int len = 0;int findm(char *t,int p) {int r = 0;for(int i=0;i<3;i++)switch (t[p+i]){case 'T':r = r * 4;break;case 'C':r = r * 4 + 1;break;case 'A':r = r * 4 + 2;break;case 'G':r = r * 4 + 3;break;default:break;}return r;}int scandna(char *t) {int starterlist[90] = {}, starternum = 0;int endlist[90] = {}, endnum = 0;int startp = -1, endp = -1;for (int i = 0; i < len - 2; i++) {if (t[i] == 'A') {if (t[i + 1] == 'T'&& t[i + 2] == 'G') {starterlist[starternum++] = i;i += 2;}}}if (starternum == 0)return 0;for (int i = 0; i < len - 2; i++) {if (t[i] == 'T') {if ((t[i + 1] == 'A' && t[i + 2] == 'G') || (t[i + 1] == 'G' && t[i + 2] == 'A') || (t[i + 1] == 'A' && t[i + 2] == 'A')) {endlist[endnum++] = i;i += 2;}}}if (endnum == 0)return 0;for (int i = 0; i < starternum; i++) {for (int j = 0; j < endnum; j++) {if (endlist[j] > starterlist[i] + 3 && (endlist[j] - starterlist[i]) % 3 == 0) {//if (startp == -1) {startp = starterlist[i];endp = endlist[j];break;//}}}if (startp != -1)break;}if (startp == -1)return 0;for (int i = startp + 3; i < endp; i += 3) {int l = 0;l = findm(t, i);if (i + 3 < endp) {printf("%s-", map[l]);}else {printf("%s\n", map[l]);}}return 1;}void makes3() {for (int i = 0; i < len; i++) {switch (s[i]){case 'T':sv[i] = 'A';break;case 'A':sv[i] = 'T';break;case 'C':sv[i] = 'G';break;case 'G':sv[i] = 'C';break;default:break;}}for (int i = 0; i < len; i++) {rs[i] = s[len -1 - i];rsv[i] = sv[len - 1 - i];}sv[len] = rs[len] = rsv[len] = '\0';}int main() {while (scanf("%s", s) != EOF && s[0] != '*') {int result = 0;len = strlen(s);makes3();result = scandna(s);if (result == 0)result = scandna(rs);if (result == 0)result = scandna(rsv);if (result == 0)result = scandna(sv);if (result == 0) {printf("*** No translatable DNA found ***\n");}}return 0;}

1542:DNA Translation

  • 查看
  • 提交
  • 统计
  • 提示
  • 提问
总时间限制: 
1000ms 
内存限制: 
65536kB
描述
Deoxyribonucleic acid (DNA) is composed of a sequence of nucleotide bases paired together to form a double-stranded helix structure. Through a series of complex biochemical processes the nucleotide sequences in an organism's DNA are translated into the proteins it requires for life. The object of this problem is to write a computer program which accepts a DNA strand and reports the protein generated, if any, from the DNA strand. 

The nucleotide bases from which DNA is built are adenine, cytosine, guanine, and thymine (hereafter referred to as A, C, G, and T, respectively). These bases bond together in a chain to form half of a DNA strand. The other half of the DNA strand is a similar chain, but each nucleotide is replaced by its complementary base. The bases A and T are complementary, as are the bases C and G. These two "half-strands" of DNA are then bonded by the pairing of the complementary bases to form a strand of DNA. 

Typically a DNA strand is listed by simply writing down the bases which form the primary strand (the complementary strand can always be created by writing the complements of the bases in the primary strand). For example, the sequence TACTCGTAATTCACT represents a DNA strand whose complement would be ATGAGCATTAAGTGA. Note that A is always paired with T, and C is always paired with G. 

From a primary strand of DNA, a strand of ribonucleic acid (RNA) known as messenger RNA (mRNA for short) is produced in a process known as transcription. The transcribed mRNA is identical to the complementary DNA strand with the exception that thymine is replaced by a nucleotide known as uracil (hereafter referred to as U). For example, the mRNA strand for the DNA in the previous paragraph would be AUGAGCAUUAAGUGA. 

It is the sequence of bases in the mRNA which determines the protein that will be synthesized. The bases in the mRNA can be viewed as a collection of codons, each codon having exactly three bases. The codon AUG marks the start of a protein sequence, and any of the codons UAA, UAG, or UGA marks the end of the sequence. The one or more codons between the start and termination codons represent the sequence of amino acids to be synthesized to form a protein. For example, the mRNA codon AGC corresponds to the amino acid serine (Ser), AUU corresponds to isoleucine (Ile), and AAG corresponds to lysine (Lys). So, the protein formed from the example mRNA in the previous paragraph is, in its abbreviated form, Ser-Ile-Lys. 

The complete genetic code from which codons are translated into amino acids is shown in the table below (note that only the amino acid abbreviations are shown). It should also be noted that the sequence AUG, which has already been identified as the start sequence, can also correspond to the amino acid methionine (Met). So, the first AUG in a mRNA strand is the start sequence, but subsequent AUG codons are translated normally into the Met amino acid. 
First base in codonSecond base in codonThird base in codonUCAGUPheSerTyrCysUPheSerTyrCysCLeuSer------ALeuSer---TrpGCLeuProHisArgULeuProHisArgCLeuProGlnArgALeuProGlnArgGAIleThrAsnSerUIleThrAsnSerCIleThrLysArgAMetThrLysArgGGValAlaAspGlyUValAlaAspGlyCValAlaGluGlyAValAlaGluGlyG
输入
The input for this program consists of strands of DNA sequences, one strand per line, from which the protein it generates, if any, should be determined and output. The given DNA strand may be either the primary or the complementary DNA strand, and it may appear in either forward or reverse order, and the start and termination sequences do not necessarily appear at the ends of the strand. For example, a given input DNA strand to form the protein Ser-Ile-Lys could be any of ATACTCGTAATTCACTCC, CCTCACTTAATGCTCATA, TATGAGCATTAAGTGAGG, or GGAGTGAATTACGAGTAT. The input will be terminated by a line containing a single asterisk character.
输出
You may assume the input to contain only valid, upper-case, DNA nucleotide base letters (A, C, G, and T). No input line will exceed 255 characters in length. There will be no blank lines or spaces in the input. Some sequences, though valid DNA strands, do not produce valid protein sequences; the string "*** No translatable DNA found ***" should be output when an input DNA strand does not translate into a valid protein.
样例输入
ATACTCGTAATTCACTCCCACCTGTACACAGAGGTAACTTAGTTAATACGACATAATTATGCCTTGATATGGAGAACTCATTAGATAAAGTGTATGTTGAATTATATAAAACGGGCATGAATGATGATGGCTTGA*
样例输出
Ser-Ile-LysCys-Leu-HisSer-Tyr*** No translatable DNA found ***Leu-Asn-Tyr-Ile-Lys-Arg-AlaMet-Met-Ala
提示
设输入串为S,与S互补的DNA串为Sv,依次将下列串作为primary DNA strand进行测试:
1)Sv
2)Sv的逆序Sv'
3)S的逆序S'
4)S
来源
Mid-Central USA 1995


思路:在四种可能的串中,找到合法的启动子和终止子,合法意味着启动子和终止子之间碱基的个数要是3的倍数,且启动子和终止子之间至少要有一个密码子的位置,终止子的位置要比启动子靠后。

密码子和对应的氨基酸用一个map来映射就好了,过程不复杂。