Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <set>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <cassert>
- #include <queue>
- #include <fstream>
- using namespace std;
- typedef long long li;
- typedef long double ld;
- #define forn(i, n) for (int i = 0; i < int(n); ++i)
- #define pb push_back
- #define mp make_pair
- #define all(v) v.begin(),v.end()
- #define EPS 1e-9
- #define PI 3.1415926535897932384626433832795
- int gcd (int a, int b) {
- return b ? gcd (b, a % b) : a;
- }
- int main() {
- srand(time(NULL));
- ifstream key_stream("key.txt");
- ifstream text_stream("text.txt");
- freopen("output.txt", "w", stdout);
- string alph = "абвгдежзийклмнопрстуфхцчшщъыьэюя";
- map <char, bool> check;
- forn (i, alph.size())
- check[alph[i]] = false;
- string key;
- key_stream >> key;
- if (key.size() < 3) {
- cout << "INCORRECT KEY" << endl;
- return 0;
- }
- if (key.size() > 7)
- key = key.substr(0, 7);
- string temp[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
- map <char, string> alph_to_pair;
- int alph_cnt = 0;
- forn (i, key.size()) {
- if (!check[key[i]]) {
- alph_to_pair[key[i]] = temp[i];
- check[key[i]] = true;
- alph_cnt++;
- }
- }
- int alph_idx = 0;
- for (int i = 7; i < 10; i++) {
- forn (j, 10) {
- if (alph_cnt >= alph.size() || alph_idx >= alph.size())
- continue;
- while (check[alph[alph_idx]])
- alph_idx++;
- if (!check[alph[alph_idx]]) {
- check[alph[alph_idx]] = true;
- alph_to_pair[alph[alph_idx]] = temp[i] + temp[j];
- alph_idx++, alph_cnt++;
- }
- }
- }
- string result = "";
- while (!text_stream.eof()) {
- string text;
- text_stream >> text;
- forn (i, text.size()) {
- if (text[i] >= 'А' && text[i] <= 'Я')
- text[i] += 'а' - 'А';
- result += alph_to_pair[text[i]];
- }
- }
- forn (i, result.size()) {
- cout << alph[result[i] - '0'];
- }
- return 0;
- }
- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <set>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <cassert>
- #include <queue>
- #include <fstream>
- using namespace std;
- typedef long long li;
- typedef long double ld;
- #define forn(i, n) for (int i = 0; i < int(n); ++i)
- #define pb push_back
- #define mp make_pair
- #define all(v) v.begin(),v.end()
- #define EPS 1e-9
- #define PI 3.1415926535897932384626433832795
- int gcd (int a, int b) {
- return b ? gcd (b, a % b) : a;
- }
- string to_string (int t) {
- if (t == 0)
- return "0";
- string result = "";
- while (t > 0) {
- result += '0' + t % 10;
- t /= 10;
- }
- return result;
- }
- int main() {
- srand(time(NULL));
- ifstream key_stream("key.txt");
- ifstream text_stream("text.txt");
- freopen("output.txt", "w", stdout);
- string alph = "абвгдежзийклмнопрстуфхцчшщъыьэюя";
- map <char, bool> check;
- forn (i, alph.size())
- check[alph[i]] = false;
- string key;
- key_stream >> key;
- if (key.size() < 3) {
- cout << "INCORRECT KEY" << endl;
- return 0;
- }
- if (key.size() > 7)
- key = key.substr(0, 7);
- string temp[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
- map <string, char> pair_to_alph;
- int alph_idx = 0, alph_cnt = 0;
- forn (i, key.size()) {
- if (!check[key[i]]) {
- pair_to_alph[temp[i]] = key[i];
- alph_cnt++;
- check[key[i]] = true;
- }
- }
- for (int i = 7; i < 10; i++) {
- forn (j, 10) {
- if (alph_cnt >= alph.size() || alph_idx >= alph.size())
- continue;
- while (check[alph[alph_idx]])
- alph_idx++;
- if (!check[alph[alph_idx]]) {
- check[alph[alph_idx]] = true;
- pair_to_alph[temp[i] + temp[j]] = alph[alph_idx];
- alph_idx++, alph_cnt++;
- }
- }
- }
- string text;
- text_stream >> text;
- for (size_t i = 0; i < text.size(); i += 2) {
- if (text[i] != alph[8] && text[i] != alph[9] && text[i] != alph[0]) {
- int idx = alph.find(text[i]);
- string ss = to_string(idx);
- cout << pair_to_alph[ss];
- i--;
- } else {
- int idx1 = alph.find(text[i]), idx2 = alph.find(text[i + 1]);
- string ss = to_string(idx1) + to_string(idx2);
- cout << pair_to_alph[ss];
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement