Advertisement
krasio12356

PasswordGenerator

Apr 17th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4.  
  5. using namespace std;
  6.  
  7.                                // PasswordGenerator
  8. int main()
  9. {
  10.     int carry = 0;
  11.     int a, b, c, d, e, f, n;
  12.     string s;
  13.     char ch;
  14.     getline(cin, s);
  15.     a = stoi(s);
  16.     getline(cin, s);
  17.     ch = toupper(s[0]);
  18.     b = ch - 'A' + 1;
  19.     getline(cin, s);
  20.     ch = tolower(s[0]);
  21.     c = ch - 'a' + 1;
  22.     cin >> d >> e >> f >> n;
  23.     int f1 = n % f + carry;
  24.     if (f1 == 0)
  25.     {
  26.         f1 = f;
  27.         carry = 0;
  28.     }
  29.     else carry = 1;
  30.     n = n / f;
  31.     if (n == 0)
  32.     {
  33.         cout << "1Aa11" << f1 << endl;
  34.         return 0;
  35.     }
  36.     int e1 = n % e + carry;
  37.     if (e1 == 0)
  38.     {
  39.         e1 = e;
  40.         carry = 0;
  41.     }
  42.     else
  43.     {
  44.         carry = 1;
  45.     }
  46.     n = n / e;
  47.     if (n == 0)
  48.     {
  49.         cout << "1Aa1" << e1 << f1 << endl;
  50.         return 0;
  51.     }
  52.     int d1 = n % d + carry;
  53.     if (d1 == 0)
  54.     {
  55.         d1 = d;
  56.         carry = 0;
  57.     }
  58.     else
  59.     {
  60.         carry = 1;
  61.     }
  62.     n = n / d;
  63.     if (n == 0)
  64.     {
  65.         cout << "1Aa" << d1 << e1 << f1 << endl;
  66.         return 0;
  67.     }
  68.     int c1 = n % c + carry;
  69.     if (c1 == 0)
  70.     {
  71.         c1 = c;
  72.         carry = 0;
  73.     }
  74.     else
  75.     {
  76.         carry = 1;
  77.     }
  78.     n = n / c;
  79.     if (n == 0)
  80.     {
  81.         cout << "1A" << (char)('a' + c1 - 1) << d1 << e1 << f1 << endl;
  82.         return 0;
  83.     }
  84.     int b1 = n % b + carry;
  85.     if (b1 == 0)
  86.     {
  87.         b1 = b;
  88.         carry = 0;
  89.     }
  90.     else
  91.     {
  92.         carry = 1;
  93.     }
  94.     n = n / b;
  95.     if (n == 0)
  96.     {
  97.         cout << "1" << (char)('A' + b1 - 1) << (char)('a' + c1 - 1) << d1 << e1 << f1 << endl;
  98.         return 0;
  99.     }
  100.     if (n > a)
  101.     {
  102.         cout << "No password on this position" << endl;
  103.         return 0;
  104.     }
  105.     if (n == a)
  106.     {
  107.         if (carry == 1)
  108.         {
  109.             cout << "No password on this position" << endl;
  110.             return 0;
  111.         }
  112.     }
  113.     cout << n + carry << (char)('A' + b1 - 1) << (char)('a' + c1 - 1) << d1 << e1 << f1 << endl;
  114.     return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement