Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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 main () {
- ifstream key_stream("key.txt");
- ifstream text_stream("text.txt");
- freopen("output.txt", "w", stdout);
- string alph = "абвгдезжиклмнопрстуфцчхшщьъэюя0123456789!,.?", key = "";
- bool contain_in_alph[44];
- forn (i, alph.size())
- contain_in_alph[i] = false;
- while (!key_stream.eof()) {
- string temp;
- key_stream >> temp;
- forn (i, temp.size()) {
- temp[i] += (temp[i] >= 'A' && temp[i] <= 'Я') ? ('а' - 'А') : 0;
- int idx = alph.find(temp[i]);
- if (!contain_in_alph[idx])
- contain_in_alph[idx] = true, key += temp[i];
- }
- }
- if (key.size() < alph.size() / 2) {
- cout << "Ключ некорректен" << endl;
- return 0;
- }
- forn (i, alph.size())
- if (!contain_in_alph[i])
- key += alph[i], contain_in_alph[i] = true;
- string result = "";
- while (!text_stream.eof()) {
- string temp;
- text_stream >> temp;
- forn (i, temp.size()) {
- bool fl = false;
- if (temp[i] >= 'А' && temp[i] <= 'Я') {
- temp[i] += 'а' - 'А';
- fl = !fl;
- }
- int idx = key.find(temp[i]);
- result += (key[(idx + (key.size() / 2)) % key.size()] - ((fl) ? ('а' - 'А') : 0));
- }
- result += " ";
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement