fork download
  1. using System;
  2.  
  3.  
  4. namespace SE310
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. //*** DO NOT CHANGE THE CODE IN THE MAIN METHOD *******
  11.  
  12. /*To test your code:
  13.   1- run the VPL (Ctr+F11)
  14.   2- input the integers of the array on the console like 7 1 2 3 4
  15.   3- input the k like 2
  16.   the output will be> 1,7,4
  17.   */
  18. /*
  19.   To evaluate your code (if evaluate is enabled):
  20.   1- Click on the evaluate button (Shift+F11)
  21.   2- the output of the evaluate will be shown on the right panel.
  22.   */
  23. try
  24. {
  25. string input1 = Console.ReadLine();
  26. string input2 = Console.ReadLine();
  27. string[] Astr = input1.Split(' ');
  28. int[] A = null;
  29. if (Astr.Length == 1)
  30. {
  31. int x;
  32. if (int.TryParse(Astr[0], out x))
  33. A = new int[] { x };
  34. }
  35. else
  36. {
  37. A = Array.ConvertAll(Astr, s => int.Parse(s));
  38. }
  39. int k = int.Parse(input2);
  40. Console.WriteLine(FindAll(A, k));
  41. }
  42. catch (Exception e)
  43. {
  44. Console.WriteLine("wrong");
  45. }
  46.  
  47. }
  48. public static string FindAll(int[] a, int k)
  49. {
  50. if (a == null || a.Length == 0)
  51. return "-1,-1,-1";
  52.  
  53. int min = a[0];
  54. int max = a[0];
  55. int[] sortedUnique = new int[a.Length];
  56. Array.Copy(a, sortedUnique, a.Length);
  57.  
  58. for (int i = 1; i < a.Length; i++)
  59. {
  60. if (a[i] < min)
  61. min = a[i];
  62. if (a[i] > max)
  63. max = a[i];
  64. }
  65.  
  66. for (int i = 0; i < sortedUnique.Length - 1; i++)
  67. {
  68. for (int j = 0; j < sortedUnique.Length - 1 - i; j++)
  69. {
  70. if (sortedUnique[j] < sortedUnique[j + 1])
  71. {
  72. int temp = sortedUnique[j];
  73. sortedUnique[j] = sortedUnique[j + 1];
  74. sortedUnique[j + 1] = temp;
  75. }
  76. }
  77. }
  78.  
  79. int newSize = 0;
  80. for (int i = 0; i < sortedUnique.Length; i++)
  81. {
  82. if (i == 0 || sortedUnique[i] != sortedUnique[i - 1])
  83. {
  84. sortedUnique[newSize] = sortedUnique[i];
  85. newSize++;
  86. }
  87. }
  88.  
  89. Array.Resize(ref sortedUnique, newSize);
  90.  
  91. int kth = -1;
  92. if (k <= sortedUnique.Length)
  93. kth = sortedUnique[k - 1];
  94.  
  95. return $"{min},{max},{kth}";
  96. }
  97.  
  98. }
  99. }
Success #stdin #stdout 0.06s 27896KB
stdin
Standard input is empty
stdout
wrong