Advertisement
Guest User

Gotowe :)

a guest
Jan 29th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. using System;
  2.  
  3. class GFG
  4. {
  5.  
  6.  
  7.  
  8. public static int j = 0;
  9.  
  10. static void printAllUniqueParts(int n,int []tab)
  11. {
  12. int[] p = new int[n];
  13. int k = 0;
  14. p[k] = n;
  15.  
  16. while (true)
  17. {
  18.  
  19. for (int i = 0; i < n; i++, j++)
  20. {
  21. if (p[i] != 0)
  22. {
  23. tab[j] = p[i];
  24. }
  25. }
  26. int rem_val = 0;
  27.  
  28. while (k >= 0 && p[k] == 1)
  29. {
  30. rem_val += p[k];
  31. k--;
  32.  
  33. }
  34. if (k < 0)
  35. return;
  36. p[k]--;
  37. rem_val++;
  38. while (rem_val > p[k])
  39. {
  40. p[k + 1] = p[k];
  41. rem_val = rem_val - p[k];
  42. k++;
  43. }
  44. p[k + 1] = rem_val;
  45. k++;
  46.  
  47. }
  48. }
  49. public static void Main()
  50. {
  51. Console.Write("Podaj ilosc: ");
  52. string s1 = Console.ReadLine();
  53. int ilosc = int.Parse(s1);
  54.  
  55. for (int i = 0; i < ilosc; i++)
  56. {
  57. Console.Write("Podaj liczbe: ");
  58. string s2 = Console.ReadLine();
  59. int liczba = int.Parse(s2);
  60.  
  61. int[] tab = new int[10000];
  62. printAllUniqueParts(liczba, tab);
  63.  
  64.  
  65. int a = 0;
  66. while (j >= 0)
  67. {
  68. if (tab[j] != 0)
  69. {
  70. a = 0;
  71. Console.Write(tab[j] + " ");
  72. a++;
  73. }
  74. else
  75. {
  76. a--;
  77. if (a >= 0)
  78. Console.WriteLine();
  79. }
  80. j--;
  81. }
  82. j = 0;
  83.  
  84. Console.WriteLine();
  85. Console.WriteLine();
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement