fork download
  1. class CyclopeptideSequencing
  2. {
  3. static int GetMass(List<int> spectrum)
  4. {
  5. int i;
  6. int mass = 0;
  7. for (i = 0; i < spectrum.Count; i++)
  8. {
  9. mass += spectrum[i];
  10. }
  11. return mass;
  12. }
  13.  
  14. static bool NextPermutation(int[] numList)
  15. {
  16. int largestIndex = -1;
  17. for (int i = numList.Length - 2; i >= 0; i--)
  18. {
  19. if (numList[i] < numList[i + 1])
  20. {
  21. largestIndex = i;
  22. break;
  23. }
  24. }
  25.  
  26. if (largestIndex < 0) return false;
  27.  
  28. int largestIndex2 = -1;
  29. for (int i = numList.Length - 1; i >= 0; i--)
  30. {
  31. if (numList[largestIndex] < numList[i])
  32. {
  33. largestIndex2 = i;
  34. break;
  35. }
  36. }
  37.  
  38. int tmp = numList[largestIndex];
  39. numList[largestIndex] = numList[largestIndex2];
  40. numList[largestIndex2] = tmp;
  41.  
  42. for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--)
  43. {
  44. tmp = numList[i];
  45. numList[i] = numList[j];
  46. numList[j] = tmp;
  47. }
  48.  
  49. return true;
  50. }
  51.  
  52. static int GetScore(List<int> spectrum1, List<int> spectrum2, int n2)
  53. {
  54. int i, j, curr, score = 0;
  55.  
  56. /* first find the theoretical spectrum of the peptide */
  57. List<int> theospectrum = new List<int>();
  58. List<int> list1 = spectrum1.ToList();
  59. List<int> list2 = spectrum2.ToList();
  60. string go = "";
  61.  
  62. theospectrum.Add(0);
  63. curr = 1; /* obtain linear permutations of length 1 */
  64. for (i = 0; i < n2; i++)
  65. {
  66. theospectrum.Add(spectrum2[i]);
  67. }
  68.  
  69.  
  70. if (GetMass(spectrum2) == spectrum1[spectrum1.Count - 1])
  71. {
  72. for (i = 0; i < n2; i++) {
  73. list2.Add(spectrum2[i]);
  74. }
  75.  
  76. curr = 1;
  77. while (curr < (n2 - 1))
  78. {
  79. /* get subpeptides of length curr + 1 */
  80. for (i = 0; i <= n2 - 1; i++)
  81. {
  82. int added = 0;
  83. for (j = i; j < i + curr + 1; j++)
  84. {
  85. added += list2[j];
  86. }
  87. theospectrum.Add(added);
  88. }
  89. curr++;
  90. }
  91.  
  92. int added2 = 0;
  93. for (i = 0; i < n2; i++)
  94. {
  95. added2 += spectrum2[i];
  96. }
  97. theospectrum.Add(added2);
  98. }
  99. else
  100. {
  101. curr = 1;
  102. while (curr < (n2 - 1))
  103. {
  104. /* get subpeptides of length curr + 1 */
  105. for (i = 0; i < n2 - curr; i++)
  106. {
  107. int added = 0;
  108. for (j = i; j < i + curr + 1; j++)
  109. {
  110. added += spectrum2[j];
  111. }
  112. theospectrum.Add(added);
  113. }
  114. curr++;
  115. }
  116.  
  117. int added2 = 0;
  118. for (i = 0; i < n2; i++)
  119. {
  120. added2 += spectrum2[i];
  121. }
  122. theospectrum.Add(added2);
  123. }
  124.  
  125. for (i = 0; i < theospectrum.Count; i++)
  126. {
  127. if (list1.Contains(theospectrum[i]))
  128. {
  129. score++;
  130. list1.Remove(theospectrum[i]);
  131. }
  132. }
  133.  
  134. return score;
  135. }
  136. static void Main(string[] args)
  137. {
  138. string n_str = Console.ReadLine();
  139. int n = Convert.ToInt16(n_str);
  140. int i, j, k, leaderlength = 0;
  141. string currConcat = Console.ReadLine();
  142. string input = "";
  143. string output = "";
  144. int[] integerMassTable = new int[] { 57, 71, 87, 97, 99, 101, 103, 113, 114, 115, 128, 129, 131, 137, 147, 156, 163, 186 };
  145. List<int> integerMassList = integerMassTable.ToList();
  146. List<int> integersUsed = new List<int>();
  147. List<int> spectrumList;
  148. List<List<int>> leaderboard = new List<List<int>>();
  149. List<int> leaderpeptide;
  150. int curr = 0;
  151. int prevmax = -1;
  152.  
  153. while (currConcat != null)
  154. {
  155. input += currConcat;
  156. currConcat = Console.ReadLine();
  157. }
  158.  
  159. string[] spectrum_str = input.Split();
  160. int[] spectrum = new int[spectrum_str.Length];
  161. for (i = 0; i < spectrum_str.Length; i++)
  162. {
  163. spectrum[i] = Convert.ToInt16(spectrum_str[i]);
  164. }
  165. spectrumList = spectrum.ToList();
  166.  
  167. /* create initial peptides */
  168. leaderboard.Add(new List<int>());
  169. leaderboard[0].Add(0);
  170. leaderpeptide = leaderboard[0];
  171. leaderlength = 1;
  172.  
  173. for (i = 0; i < integerMassList.Count; i++)
  174. {
  175. if (spectrumList.Contains(integerMassList[i]))
  176. {
  177. if (!integersUsed.Contains(integerMassList[i]))
  178. {
  179. integersUsed.Add(integerMassList[i]);
  180. leaderboard.Add(new List<int>());
  181. leaderboard[leaderlength].Add(integerMassList[i]);
  182. leaderlength++;
  183. }
  184. }
  185. }
  186.  
  187. /* LeaderboardCyclopeptideSequencing */
  188. while (leaderlength != 0)
  189. {
  190.  
  191. /* branching step */
  192. int previousLength = leaderlength;
  193. List<List<int>> previousLeaderboard = leaderboard.ToList();
  194. leaderboard.Clear();
  195. leaderlength = 0;
  196. for (i = 1; i < previousLength; i++)
  197. {
  198. for (j = 0; j < integerMassTable.Length; j++)
  199. {
  200. List<int> list = previousLeaderboard[i].ToList();
  201. list.Add(integerMassTable[j]);
  202. leaderboard.Add(list);
  203. leaderlength++;
  204. }
  205. }
  206.  
  207. /* matching step */
  208. List<int> indexesToRemove = new List<int>();
  209. List<int> indexesToKeep = new List<int>();
  210. for (i = 0; i < leaderlength; i++)
  211. {
  212. if (GetMass(leaderboard[i]) == spectrum.Last())
  213. {
  214. if (GetScore(spectrumList, leaderboard[i], leaderboard[i].Count) >= GetScore(spectrumList, leaderpeptide, leaderpeptide.Count))
  215. {
  216. leaderpeptide = leaderboard[i].ToList();
  217. leaderboard.RemoveAt(i);
  218. leaderlength--;
  219. }
  220. }
  221. else if (GetMass(leaderboard[i]) > spectrum.Last())
  222. {
  223. /* remove leaderboard[i] */
  224. indexesToRemove.Add(i);
  225. }
  226. }
  227.  
  228.  
  229. List<List<int>> newLeaderboard = leaderboard.ToList();
  230. leaderboard.Clear();
  231. for (i = 0; i < leaderlength; i++)
  232. {
  233. if (!indexesToRemove.Contains(i))
  234. {
  235. indexesToKeep.Add(i);
  236. }
  237. }
  238. indexesToKeep.Sort();
  239. for (i = 0; i < indexesToKeep.Count; i++)
  240. {
  241. leaderboard.Add(newLeaderboard[indexesToKeep[i]].ToList());
  242. }
  243. leaderlength = leaderboard.Count;
  244.  
  245. /* bounding step */
  246. int[] allScores = new int[leaderlength];
  247. indexesToKeep.Clear();
  248. List<int> highestScores = new List<int>();
  249.  
  250. for (i = 0; i < leaderlength; i++)
  251. {
  252. int score = GetScore(spectrumList, leaderboard[i], leaderboard[i].Count);
  253. allScores[i] = score;
  254. highestScores.Add(score);
  255. }
  256.  
  257. highestScores.Sort();
  258. while (highestScores.Count > n)
  259. {
  260. highestScores.RemoveAt(0);
  261. }
  262.  
  263. i = 0;
  264. previousLeaderboard = leaderboard.ToList();
  265. leaderboard.Clear();
  266. while (highestScores.Count > 0)
  267. {
  268. if (i == leaderlength)
  269. {
  270. i = 0;
  271. }
  272. if (allScores[i] == highestScores[0])
  273. {
  274. leaderboard.Add(previousLeaderboard[i].ToList());
  275. highestScores.RemoveAt(0);
  276. }
  277. i++;
  278. }
  279. leaderlength = leaderboard.Count;
  280.  
  281. if (curr == 20)
  282. {
  283. break;
  284. }
  285. curr++;
  286.  
  287. }
  288.  
  289. for (i = 0; i < leaderpeptide.Count; i++)
  290. {
  291. output += leaderpeptide[i].ToString();
  292. if (i != leaderpeptide.Count - 1)
  293. {
  294. output += "-";
  295. }
  296. }
  297.  
  298. Console.WriteLine(output);
  299. Thread.Sleep(50000);
  300. }
  301. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: cannot find symbol
        static int GetMass(List<int> spectrum)
                           ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:3: error: unexpected type
        static int GetMass(List<int> spectrum)
                                ^
  required: reference
  found:    int
Main.java:14: error: cannot find symbol
        static bool NextPermutation(int[] numList)
               ^
  symbol:   class bool
  location: class CyclopeptideSequencing
Main.java:52: error: cannot find symbol
        static int GetScore(List<int> spectrum1, List<int> spectrum2, int n2)
                            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:52: error: unexpected type
        static int GetScore(List<int> spectrum1, List<int> spectrum2, int n2)
                                 ^
  required: reference
  found:    int
Main.java:52: error: cannot find symbol
        static int GetScore(List<int> spectrum1, List<int> spectrum2, int n2)
                                                 ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:52: error: unexpected type
        static int GetScore(List<int> spectrum1, List<int> spectrum2, int n2)
                                                      ^
  required: reference
  found:    int
Main.java:136: error: cannot find symbol
        static void Main(string[] args)
                         ^
  symbol:   class string
  location: class CyclopeptideSequencing
Main.java:17: error: cannot find symbol
            for (int i = numList.Length - 2; i >= 0; i--)
                                ^
  symbol:   variable Length
  location: variable numList of type int[]
Main.java:29: error: cannot find symbol
            for (int i = numList.Length - 1; i >= 0; i--)
                                ^
  symbol:   variable Length
  location: variable numList of type int[]
Main.java:42: error: cannot find symbol
            for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--)
                                                      ^
  symbol:   variable Length
  location: variable numList of type int[]
Main.java:57: error: cannot find symbol
            List<int> theospectrum = new List<int>();
            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:57: error: unexpected type
            List<int> theospectrum = new List<int>();
                 ^
  required: reference
  found:    int
Main.java:57: error: cannot find symbol
            List<int> theospectrum = new List<int>();
                                         ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:57: error: unexpected type
            List<int> theospectrum = new List<int>();
                                              ^
  required: reference
  found:    int
Main.java:58: error: cannot find symbol
            List<int> list1 = spectrum1.ToList();
            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:58: error: unexpected type
            List<int> list1 = spectrum1.ToList();
                 ^
  required: reference
  found:    int
Main.java:59: error: cannot find symbol
            List<int> list2 = spectrum2.ToList();
            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:59: error: unexpected type
            List<int> list2 = spectrum2.ToList();
                 ^
  required: reference
  found:    int
Main.java:60: error: cannot find symbol
            string go = "";
            ^
  symbol:   class string
  location: class CyclopeptideSequencing
Main.java:138: error: cannot find symbol
            string n_str = Console.ReadLine();
            ^
  symbol:   class string
  location: class CyclopeptideSequencing
Main.java:138: error: cannot find symbol
            string n_str = Console.ReadLine();
                           ^
  symbol:   variable Console
  location: class CyclopeptideSequencing
Main.java:139: error: cannot find symbol
            int n = Convert.ToInt16(n_str);
                    ^
  symbol:   variable Convert
  location: class CyclopeptideSequencing
Main.java:141: error: cannot find symbol
            string currConcat = Console.ReadLine();
            ^
  symbol:   class string
  location: class CyclopeptideSequencing
Main.java:141: error: cannot find symbol
            string currConcat = Console.ReadLine();
                                ^
  symbol:   variable Console
  location: class CyclopeptideSequencing
Main.java:142: error: cannot find symbol
            string input = "";
            ^
  symbol:   class string
  location: class CyclopeptideSequencing
Main.java:143: error: cannot find symbol
            string output = "";
            ^
  symbol:   class string
  location: class CyclopeptideSequencing
Main.java:145: error: cannot find symbol
            List<int> integerMassList = integerMassTable.ToList();
            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:145: error: unexpected type
            List<int> integerMassList = integerMassTable.ToList();
                 ^
  required: reference
  found:    int
Main.java:145: error: cannot find symbol
            List<int> integerMassList = integerMassTable.ToList();
                                                        ^
  symbol:   method ToList()
  location: variable integerMassTable of type int[]
Main.java:146: error: cannot find symbol
            List<int> integersUsed = new List<int>();
            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:146: error: unexpected type
            List<int> integersUsed = new List<int>();
                 ^
  required: reference
  found:    int
Main.java:146: error: cannot find symbol
            List<int> integersUsed = new List<int>();
                                         ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:146: error: unexpected type
            List<int> integersUsed = new List<int>();
                                              ^
  required: reference
  found:    int
Main.java:147: error: cannot find symbol
            List<int> spectrumList;
            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:147: error: unexpected type
            List<int> spectrumList;
                 ^
  required: reference
  found:    int
Main.java:148: error: cannot find symbol
            List<List<int>> leaderboard = new List<List<int>>();
            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:148: error: cannot find symbol
            List<List<int>> leaderboard = new List<List<int>>();
                 ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:148: error: unexpected type
            List<List<int>> leaderboard = new List<List<int>>();
                      ^
  required: reference
  found:    int
Main.java:148: error: cannot find symbol
            List<List<int>> leaderboard = new List<List<int>>();
                                              ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:148: error: cannot find symbol
            List<List<int>> leaderboard = new List<List<int>>();
                                                   ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:148: error: unexpected type
            List<List<int>> leaderboard = new List<List<int>>();
                                                        ^
  required: reference
  found:    int
Main.java:149: error: cannot find symbol
            List<int> leaderpeptide;
            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:149: error: unexpected type
            List<int> leaderpeptide;
                 ^
  required: reference
  found:    int
Main.java:156: error: cannot find symbol
                currConcat = Console.ReadLine();
                             ^
  symbol:   variable Console
  location: class CyclopeptideSequencing
Main.java:159: error: cannot find symbol
            string[] spectrum_str = input.Split();
            ^
  symbol:   class string
  location: class CyclopeptideSequencing
Main.java:163: error: cannot find symbol
                spectrum[i] = Convert.ToInt16(spectrum_str[i]);
                              ^
  symbol:   variable Convert
  location: class CyclopeptideSequencing
Main.java:165: error: cannot find symbol
            spectrumList = spectrum.ToList();
                                   ^
  symbol:   method ToList()
  location: variable spectrum of type int[]
Main.java:168: error: cannot find symbol
            leaderboard.Add(new List<int>());
                                ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:168: error: unexpected type
            leaderboard.Add(new List<int>());
                                     ^
  required: reference
  found:    int
Main.java:180: error: cannot find symbol
                        leaderboard.Add(new List<int>());
                                            ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:180: error: unexpected type
                        leaderboard.Add(new List<int>());
                                                 ^
  required: reference
  found:    int
Main.java:193: error: cannot find symbol
                List<List<int>> previousLeaderboard = leaderboard.ToList();
                ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:193: error: cannot find symbol
                List<List<int>> previousLeaderboard = leaderboard.ToList();
                     ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:193: error: unexpected type
                List<List<int>> previousLeaderboard = leaderboard.ToList();
                          ^
  required: reference
  found:    int
Main.java:198: error: cannot find symbol
                    for (j = 0; j < integerMassTable.Length; j++)
                                                    ^
  symbol:   variable Length
  location: variable integerMassTable of type int[]
Main.java:200: error: cannot find symbol
                        List<int> list = previousLeaderboard[i].ToList();
                        ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:200: error: unexpected type
                        List<int> list = previousLeaderboard[i].ToList();
                             ^
  required: reference
  found:    int
Main.java:208: error: cannot find symbol
                List<int> indexesToRemove = new List<int>();
                ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:208: error: unexpected type
                List<int> indexesToRemove = new List<int>();
                     ^
  required: reference
  found:    int
Main.java:208: error: cannot find symbol
                List<int> indexesToRemove = new List<int>();
                                                ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:208: error: unexpected type
                List<int> indexesToRemove = new List<int>();
                                                     ^
  required: reference
  found:    int
Main.java:209: error: cannot find symbol
                List<int> indexesToKeep = new List<int>();
                ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:209: error: unexpected type
                List<int> indexesToKeep = new List<int>();
                     ^
  required: reference
  found:    int
Main.java:209: error: cannot find symbol
                List<int> indexesToKeep = new List<int>();
                                              ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:209: error: unexpected type
                List<int> indexesToKeep = new List<int>();
                                                   ^
  required: reference
  found:    int
Main.java:212: error: cannot find symbol
                    if (GetMass(leaderboard[i]) == spectrum.Last())
                                                           ^
  symbol:   method Last()
  location: variable spectrum of type int[]
Main.java:221: error: cannot find symbol
                    else if (GetMass(leaderboard[i]) > spectrum.Last())
                                                               ^
  symbol:   method Last()
  location: variable spectrum of type int[]
Main.java:229: error: cannot find symbol
                List<List<int>> newLeaderboard = leaderboard.ToList();
                ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:229: error: cannot find symbol
                List<List<int>> newLeaderboard = leaderboard.ToList();
                     ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:229: error: unexpected type
                List<List<int>> newLeaderboard = leaderboard.ToList();
                          ^
  required: reference
  found:    int
Main.java:248: error: cannot find symbol
                List<int> highestScores = new List<int>();
                ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:248: error: unexpected type
                List<int> highestScores = new List<int>();
                     ^
  required: reference
  found:    int
Main.java:248: error: cannot find symbol
                List<int> highestScores = new List<int>();
                                              ^
  symbol:   class List
  location: class CyclopeptideSequencing
Main.java:248: error: unexpected type
                List<int> highestScores = new List<int>();
                                                   ^
  required: reference
  found:    int
Main.java:298: error: cannot find symbol
            Console.WriteLine(output);
            ^
  symbol:   variable Console
  location: class CyclopeptideSequencing
Main.java:299: error: cannot find symbol
            Thread.Sleep(50000);
                  ^
  symbol:   method Sleep(int)
  location: class Thread
77 errors
stdout
Standard output is empty