Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <cmath>
- #include <stdio.h>
- using namespace std;
- int delta = 'я' - 'а' + 1;
- double calcindex(const string &text) {
- int *A = new int [delta];
- for (int i = 0; i < delta; ++i) {
- A[i] = 0;
- }
- for (int i = 0; i < text.size(); ++i) {
- ++A[text[i] - 'а'];
- }
- double r = 0;
- for (int i = 0; i < delta; ++i) {
- r += double(A[i]) * (A[i] - 1);
- }
- return r / (text.size() * (double(text.size()) - 1));
- }
- string del_spaces(const string &str) {
- string res;
- for (int i = 0; i < str.size(); ++i) {
- if (str[i] != ' ') {
- res += str[i];
- }
- }
- return res;
- }
- string textpreproc(const string &str) {
- string res;
- for (int i = 0; i < str.size(); ++i) {
- if (str[i] >= 'а' && str[i] <= 'я') {
- res += str[i];
- }
- if (str[i] >= 'А' && str[i] <= 'Я') {
- res += str[i] - 'А' + 'а';
- }
- }
- return res;
- }
- string encode(const string &text, const string &key) {
- string res;
- for (int i = 0; i < text.size(); ++i) {
- int d = (text[i] - 'а') + key[i % key.size()] + 1;
- res += d > 'я' ? d - delta : d;
- }
- return res;
- }
- string decode(const string &text, const string &key) {
- string res;
- for (int i = 0; i < text.size(); ++i) {
- int d = int(text[i]) - key[i % key.size()] + 'а' - 1;
- res += text[i] > key[i % key.size()] ? d : d + delta;
- }
- return res;
- }
- int main() {
- setlocale(LC_ALL, "rus");
- freopen("input.txt", "r", stdin);
- string s;
- getline(cin, s);
- int n = s.size();
- vector < int > fact;
- for (int i = 2; i * i <= n; ++i) {
- while (n % i == 0) {
- fact.push_back(i);
- n /= i;
- }
- }
- if (n != 1) {
- fact.push_back(n);
- }
- for (int i = 0; i < fact.size(); ++i) {
- cout << fact[i] << " ";
- }
- return 0;
- string text = "кеккек лол, жопа";
- text = textpreproc(text);
- cout << text << "\n";
- string key = "абв";
- text = encode(text, key);
- cout << text << "\n";
- text = decode(text, key);
- cout << text << "\n"
- << calcindex(text) << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment