SHARE
TWEET

Task 3

a guest Jan 22nd, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     string s;
  10.     vector<string> words(16);
  11.     for (int i = 0; i < 16; ++i)
  12.         cin >> words[i];
  13.     cin >> s;
  14.     string letters = "ABCDEFGHIJ";
  15.     do
  16.     {
  17.         vector<int> values(10);
  18.         for (int i = 0; i < 10; ++i)
  19.             values[letters[i] - 'A'] = i;
  20.         vector<int> numbers(16);
  21.         for (int i = 0; i < 16; ++i)
  22.         {
  23.             int number = 0;
  24.             for (auto &c: words[i])
  25.                 number = number * 10 + values[c - 'A'];
  26.             numbers[i] = number;
  27.         }
  28.         bool correct = true;
  29.         for (int i = 1; correct && i < 16; ++i)
  30.             if (numbers[i] <= numbers[i - 1])
  31.                 correct = false;
  32.         if (correct)
  33.         {
  34.             int number = 0;
  35.             for (auto &c: s)
  36.                 number = number * 10 + values[c - 'A'];
  37.             cout << number;
  38.             return 0;
  39.         }
  40.     } while (next_permutation(letters.begin(), letters.end()));
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top