Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- int main() {
- vector<string> v;
- ifstream input ("/Users/alexey/Desktop/Программирование/Лабы/Laba 5/test2.txt");
- ofstream output1 ("/Users/alexey/Desktop/Программирование/Лабы/Laba 5/ответ1.txt");
- ofstream output2 ("/Users/alexey/Desktop/Программирование/Лабы/Laba 5/ответ2.txt");
- string word;
- while (input >> word){
- v.push_back(word);
- }
- long long int maxN = 0, maxLen = 0, indexN = - 1, indexLen = - 1;
- vector<int> max;
- for (int i = 0; i < v.size(); ++i) {
- long long int k = 0;
- vector<int> d;
- for (int j = 0; j < v.size(); ++j) {
- if (i == j) continue;
- if (v[j].find(v[i], 0) == 0) {
- k++;
- d.push_back(j);
- }
- }
- if (k > maxN) {
- maxN = k;
- indexN = i;
- }
- if ((k > 0) && (v[i].length() > maxLen)) {
- maxLen = v[i].length();
- indexLen = i;
- max.resize(k);
- for (int q = 0; q < k; ++q)
- max[q] = d[q];
- }
- }
- if (indexLen == -1) output1 << "NO" << endl;
- else {
- output1 << v[indexLen] << ' ';
- for (const int& index : max)
- output1 << v[index] << ' ';
- }
- if (indexN == -1) output2 << "NO" << endl;
- else output2 << v[indexN] << ' ' << maxN;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement