fork(2) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApp2
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10.  
  11. int D = Convert.ToInt32(Console.ReadLine());
  12. while (D > 0)
  13. {
  14. int N = Convert.ToInt32(Console.ReadLine());
  15.  
  16.  
  17. string[] lista = Console.ReadLine().Split(' ');
  18. List<int> listaA = new List<int>(Array.ConvertAll(lista, arrTemp =>
  19. Convert.ToInt32(arrTemp)));
  20. listaA.Sort();
  21. if (N==1)
  22. {
  23. Console.WriteLine(listaA[0]);
  24. }
  25. else
  26. {
  27. if (listaA[N - 1] == listaA[N - 2])
  28. {
  29. Console.Write($"{listaA[N - 1]} {listaA[N - 2]}");
  30. for (int i = 0; i < listaA.Count - 2; i++)
  31. {
  32. Console.Write($" {listaA[i]}");
  33. }
  34. Console.WriteLine();
  35. }
  36.  
  37.  
  38. else
  39.  
  40. {
  41. Console.Write($"{listaA[N - 1]}");
  42. for (int i = 0; i < listaA.Count - 1; i++)
  43. {
  44. Console.Write($" {listaA[i]}");
  45. }
  46. Console.WriteLine();
  47. }
  48. }
  49.  
  50.  
  51. D--;
  52. }
  53.  
  54.  
  55. }
  56. }
  57. }
  58.  
Success #stdin #stdout 0.02s 24888KB
stdin
4
5
1 2 3 4 5
5
4 5 2 3 5
2
1 1
1
1
stdout
5 1 2 3 4
5 5 2 3 4
1 1
1