Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct str {
- string s;
- vector <string> words;
- int num_of_words;
- };
- vector <str> writings;
- vector <char> stroke;
- vector <char> new_stroke;
- string normalize(string s, int num);
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- string temp;
- for (size_t i = 0; getline(cin, temp); ++i) {
- if (temp.size() != 0) {
- writings.resize(i + 1);
- temp = normalize(temp, i);
- writings[i].s = temp;
- }
- else
- --i;
- }
- double same = 0;
- for (size_t i = 0; i < writings.size(); ++i)
- for (size_t j = i; j < writings.size(); ++j) {
- if (i == j)
- continue;
- for (size_t words_1 = 0; words_1 < writings[i].num_of_words; ++words_1) {
- for (size_t words_2 = 0; words_2 < writings[j].num_of_words; ++words_2) {
- int min_len;
- min_len = min(writings[i].words[words_1].length(), writings[j].words[words_2].length());
- double c = 0;
- for (size_t k = 0; k < min_len; ++k)
- if (writings[i].words[words_1][k] == writings[j].words[words_2][k])
- ++c;
- double a = writings[i].words[words_1].length();
- double b = writings[j].words[words_2].length();
- double l = c / (a + b - c);
- if (l > 0.45)
- ++same;
- }
- }
- double len_1 = writings[i].num_of_words;
- double len_2 = writings[j].num_of_words;
- double last_k = same / (len_1 + len_2 - same);
- if (last_k > 0.25)
- printf("%d %d\n", i + 1, j + 1);
- same = 0;
- }
- }
- string normalize(string s, int num) {
- for (size_t i = 0; i < s.size(); ++i) {
- if (s[i] >= '0' && s[i] <= '9')
- stroke.push_back(s[i]);
- else if (s[i] >= 'a' && s[i] <= 'z')
- stroke.push_back(s[i]);
- else if (s[i] >= 'A' && s[i] <= 'Z')
- stroke.push_back(s[i] + 32);
- else if (s[i] == ' ')
- stroke.push_back(s[i]);
- }
- stroke.push_back('*');
- bool backspace = true;
- int counter = 0;
- string word = "";
- writings[num].num_of_words = 0;
- for (size_t i = 0; i < stroke.size() - 1; ++i) {
- if (stroke[i] == ' ') {
- if (backspace == false && i != 0) {
- new_stroke.push_back(stroke[i]);
- backspace = true;
- }
- }
- else {
- for (size_t j = i; stroke[j] != ' ' && j < stroke.size() - 1; ++j)
- counter++;
- if (counter > 3) {
- size_t j;
- for (j = i; stroke[j] != ' ' && j < stroke.size() - 1; ++j) {
- word += stroke[j];
- new_stroke.push_back(stroke[j]);
- }
- writings[num].words.resize(writings[num].num_of_words + 1);
- writings[num].words[writings[num].num_of_words] = word;
- ++writings[num].num_of_words;
- word = "";
- backspace = false;
- }
- i += counter - 1;
- counter = 0;
- }
- }
- string temp = "";
- for (size_t i = 0; i < new_stroke.size(); ++i)
- temp += new_stroke[i];
- stroke.clear();
- new_stroke.clear();
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement