Guest User

Untitled

a guest
Jun 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. double totalFunc(vector<double> l);
  8.  
  9. int main()
  10. {
  11. double n, k, t = 0;
  12. string alpha = "abcdefghijklmnopqrst";
  13. while (true)
  14. {
  15. cin >> n >> k;
  16. string result = "";
  17. if (n == 0 && k == 0) break;
  18. vector<double> letters;
  19. t = 0;
  20. for (int i = 0; i < n; i++) {
  21. double j;
  22. cin >> j;
  23. t += j;
  24. letters.push_back(j);
  25. }
  26. // MAIN PROGRAM
  27. for (int i = 0; i < t; i++)
  28. {
  29. for (int j = 0; j < n; j++)
  30. {
  31. if (letters[j] > 0) {
  32. letters[j]--;
  33. double total = totalFunc(letters);
  34. if (k < total)
  35. {
  36. result += alpha[j];
  37. break;
  38. } else {
  39. k = k - total;
  40. letters[j]++;
  41. }
  42. }
  43. }
  44. }
  45.  
  46. cout << result << endl;
  47. }
  48.  
  49. return 0;
  50. }
  51.  
  52. int UCLN(int a, int b) {
  53. while ((a != 0) && (b != 0)) {
  54. a = a%b;
  55. if (a != 0)
  56. b = b%a;
  57. }
  58. return a+b;
  59. }
  60.  
  61. double totalFunc(vector<double> l)
  62. {
  63. double n = l.size();
  64. double bigt = 0;
  65. vector<double> tarray;
  66. for(int i=0; i < n; i++)
  67. {
  68. bigt += l[i];
  69. }
  70. tarray.push_back(0);
  71. for(int i=1; i <= bigt; i++)
  72. {
  73. tarray.push_back(i);
  74. }
  75.  
  76. for(int i=0; i < n; i++)
  77. {
  78. for(int j=1; j <= l[i]; j++)
  79. {
  80. double jj = j;
  81. for(int k=1; k <= bigt; k++)
  82. {
  83. double x = UCLN(tarray[k], jj);
  84. if (x != 1)
  85. {
  86. tarray[k] = tarray[k] / x;
  87. jj = jj / x;
  88. }
  89. if (jj == 1) break;
  90. }
  91. }
  92. }
  93. double result = 1;
  94. for (int i = 1; i < tarray.size(); i++)
  95. result *= tarray[i];
  96. return result;
  97. }
Add Comment
Please, Sign In to add comment