Guest User

def

a guest
Mar 14th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <cmath>
  5. #include <stdio.h>
  6.  
  7. using namespace std;
  8.  
  9. int delta = 'я' - 'а' + 1;
  10. double calcindex(const string &text) {
  11.     int *A = new int [delta];
  12.     for (int i = 0; i < delta; ++i) {
  13.         A[i] = 0;
  14.     }
  15.     for (int i = 0; i < text.size(); ++i) {
  16.         ++A[text[i] - 'а'];
  17.     }
  18.     double r = 0;
  19.     for (int i = 0; i < delta; ++i) {
  20.         r += double(A[i]) * (A[i] - 1);
  21.     }
  22.     return r / (text.size() * (double(text.size()) - 1));
  23. }
  24.  
  25. string del_spaces(const string &str) {
  26.     string res;
  27.     for (int i = 0; i < str.size(); ++i) {
  28.         if (str[i] != ' ') {
  29.             res += str[i];
  30.         }
  31.     }
  32.     return res;
  33. }
  34.  
  35. string textpreproc(const string &str) {
  36.     string res;
  37.     for (int i = 0; i < str.size(); ++i) {
  38.         if (str[i] >= 'а' && str[i] <= 'я') {
  39.             res += str[i];
  40.         }
  41.         if (str[i] >= 'А' && str[i] <= 'Я') {
  42.             res += str[i] - 'А' + 'а';
  43.         }
  44.     }
  45.     return res;
  46. }
  47.  
  48. string encode(const string &text, const string &key) {
  49.     string res;
  50.     for (int i = 0; i < text.size(); ++i) {
  51.         int d = (text[i] - 'а') + key[i % key.size()] + 1;
  52.         res += d > 'я' ? d - delta : d;
  53.     }
  54.     return res;
  55. }
  56. string decode(const string &text, const string &key) {
  57.     string res;
  58.     for (int i = 0; i < text.size(); ++i) {
  59.         int d = int(text[i]) - key[i % key.size()] + 'а' - 1;
  60.         res += text[i] > key[i % key.size()] ? d : d + delta;
  61.     }
  62.     return res;
  63. }
  64.  
  65. int main() {
  66.  
  67.     setlocale(LC_ALL, "rus");
  68.  
  69.     freopen("input.txt", "r", stdin);
  70.  
  71.     string s;
  72.     getline(cin, s);
  73.  
  74.     int n = s.size();
  75.  
  76.     vector < int > fact;
  77.     for (int i = 2; i * i <= n; ++i) {
  78.         while (n % i == 0) {
  79.             fact.push_back(i);
  80.             n /= i;
  81.         }
  82.     }
  83.  
  84.     if (n != 1) {
  85.         fact.push_back(n);
  86.     }
  87.  
  88.     for (int i = 0; i < fact.size(); ++i) {
  89.         cout << fact[i] << " ";
  90.     }
  91.  
  92.     return 0;
  93.  
  94.     string text = "кеккек лол, жопа";
  95.     text = textpreproc(text);
  96.  
  97.     cout << text << "\n";
  98.  
  99.     string key = "абв";
  100.  
  101.     text = encode(text, key);
  102.  
  103.     cout << text << "\n";
  104.  
  105.     text = decode(text, key);
  106.  
  107.     cout << text << "\n"
  108.          << calcindex(text) << "\n";
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment