Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <map>
- #include <vector>
- using namespace std;
- void Print(const vector<string> &v)
- {
- for (int i = 0; i < v.size(); ++i)
- cout << v[i] << " ";
- cout << endl;
- }
- int main() {
- ifstream myFile;
- myFile.open("file.txt");
- map<int, vector<string>> m;
- string s;
- int line = 0;
- while (!myFile.eof()) {
- myFile >> s;
- if (s.find('.') != string::npos)
- m[line++].push_back(s);
- else
- m[line].push_back(s);
- }
- string word;
- cin >> word;
- int k = -1;
- for (auto& i : m) {
- for (int j = 0; j < i.second.size(); ++j) {
- if (i.second[j] == word){
- k = i.first;
- break;
- }
- }
- }
- if (k == -1) {
- cout << word << " has no synonyms in this file\n";
- return 0;
- }
- map<int, vector<string>>::iterator it = m.find(k);
- while ((it != m.end()) && ((*it).first == k)) {
- Print((*it++).second);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment