Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <string>
- using namespace std;
- double totalFunc(vector<double> l);
- int main()
- {
- double n, k, t = 0;
- string alpha = "abcdefghijklmnopqrst";
- while (true)
- {
- cin >> n >> k;
- string result = "";
- if (n == 0 && k == 0) break;
- vector<double> letters;
- t = 0;
- for (int i = 0; i < n; i++) {
- double j;
- cin >> j;
- t += j;
- letters.push_back(j);
- }
- // MAIN PROGRAM
- for (int i = 0; i < t; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (letters[j] > 0) {
- letters[j]--;
- double total = totalFunc(letters);
- if (k < total)
- {
- result += alpha[j];
- break;
- } else {
- k = k - total;
- letters[j]++;
- }
- }
- }
- }
- cout << result << endl;
- }
- return 0;
- }
- int UCLN(int a, int b) {
- while ((a != 0) && (b != 0)) {
- a = a%b;
- if (a != 0)
- b = b%a;
- }
- return a+b;
- }
- double totalFunc(vector<double> l)
- {
- double n = l.size();
- double bigt = 0;
- vector<double> tarray;
- for(int i=0; i < n; i++)
- {
- bigt += l[i];
- }
- tarray.push_back(0);
- for(int i=1; i <= bigt; i++)
- {
- tarray.push_back(i);
- }
- for(int i=0; i < n; i++)
- {
- for(int j=1; j <= l[i]; j++)
- {
- double jj = j;
- for(int k=1; k <= bigt; k++)
- {
- double x = UCLN(tarray[k], jj);
- if (x != 1)
- {
- tarray[k] = tarray[k] / x;
- jj = jj / x;
- }
- if (jj == 1) break;
- }
- }
- }
- double result = 1;
- for (int i = 1; i < tarray.size(); i++)
- result *= tarray[i];
- return result;
- }
Add Comment
Please, Sign In to add comment