fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace DNA_Bases
  8. {
  9. public class Program
  10. {
  11. private static Dictionary<char, char> bases;
  12. private static Dictionary<string, string> codons;
  13. private static string originalString;
  14. private static string flippedString;
  15. private static string proteinString;
  16.  
  17. public static void Main(string[] args)
  18. {
  19. originalString = Console.ReadLine();
  20. SetupDictionaries();
  21.  
  22. foreach (char dnaBase in originalString)
  23. {
  24. flippedString += bases[dnaBase];
  25. }
  26.  
  27. for (int i = 0; i < originalString.Length; i += 3)
  28. {
  29. string codon = originalString.Substring(i, 3);
  30.  
  31. proteinString += codons[codon];
  32. if (codons[codon] != "STOP")
  33. {
  34. proteinString += " ";
  35. }
  36. }
  37.  
  38. Console.WriteLine(originalString);
  39. Console.WriteLine(flippedString);
  40. Console.WriteLine(proteinString);
  41. }
  42.  
  43. private static void SetupDictionaries()
  44. {
  45. bases = new Dictionary<char, char>()
  46. {
  47. {'A', 'T'},
  48. {'T', 'A'},
  49. {'C', 'G'},
  50. {'G', 'C'}
  51. };
  52.  
  53. codons = new Dictionary<string, string>()
  54. {
  55. {"TTT", "Phe"},
  56. {"TTC", "Phe"},
  57. {"TTA", "Leu"},
  58. {"TTG", "Leu"},
  59. {"CTT", "Leu"},
  60. {"CTC", "Leu"},
  61. {"CTA", "Leu"},
  62. {"CTG", "Leu"},
  63. {"ATT", "Ile"},
  64. {"ATC", "Ile"},
  65. {"ATA", "Ile"},
  66. {"ATG", "Met"},
  67. {"GTT", "Val"},
  68. {"GTC", "Val"},
  69. {"GTA", "Val"},
  70. {"GTG", "Val"},
  71. {"TCT", "Ser"},
  72. {"TCC", "Ser"},
  73. {"TCA", "Ser"},
  74. {"TCG", "Ser"},
  75. {"CCT", "Pro"},
  76. {"CCC", "Pro"},
  77. {"CCA", "Pro"},
  78. {"CCG", "Pro"},
  79. {"ACT", "Thr"},
  80. {"ACC", "Thr"},
  81. {"ACA", "Thr"},
  82. {"ACG", "Thr"},
  83. {"GCT", "Ala"},
  84. {"GCC", "Ala"},
  85. {"GCA", "Ala"},
  86. {"GCG", "Ala"},
  87. {"TAT", "Tyr"},
  88. {"TAC", "Tyr"},
  89. {"TAA", "STOP"},
  90. {"TAG", "STOP"},
  91. {"CAT", "His"},
  92. {"CAC", "His"},
  93. {"CAA", "Gln"},
  94. {"CAG", "Gln"},
  95. {"AAT", "Asn"},
  96. {"AAC", "Asn"},
  97. {"AAA", "Lys"},
  98. {"AAG", "Lys"},
  99. {"GAT", "Asp"},
  100. {"GAC", "Asp"},
  101. {"GAA", "Glu"},
  102. {"GAG", "Glu"},
  103. {"TGT", "Cys"},
  104. {"TGC", "Cys"},
  105. {"TGA", "STOP"},
  106. {"TGG", "Trp"},
  107. {"CGT", "Arg"},
  108. {"CGC", "Arg"},
  109. {"CGA", "Arg"},
  110. {"CGG", "Arg"},
  111. {"AGT", "Ser"},
  112. {"AGC", "Ser"},
  113. {"AGA", "Arg"},
  114. {"AGG", "Arg"},
  115. {"GGT", "Gly"},
  116. {"GGC", "Gly"},
  117. {"GGA", "Gly"},
  118. {"GGG", "Gly"}
  119. };
  120. }
  121. }
  122. }
Success #stdin #stdout 0.05s 24328KB
stdin
ATGATCGATGCTCTAGCGTAG
stdout
ATGATCGATGCTCTAGCGTAG
TACTAGCTACGAGATCGCATC
Met Ile Asp Ala Leu Ala STOP