Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <fstream>
- #include <string>
- #include <utility>
- #include <sstream>
- using namespace std;
- int main()
- {
- map <string, int> myMap;
- map <int, int> myMap2;
- int last = NULL;
- ifstream in("input.txt");
- string tmp;
- int j = 0;
- int indx = 1;
- while (in >> tmp)
- {
- bool flag = true;
- for (unsigned int i = 0; i < tmp.size(); i++)
- if (!(tmp[i] == '-' || isdigit(tmp[i])))
- flag = false;
- if (flag)
- {
- stringstream ss(tmp);
- int temp;
- ss >> temp;
- last = temp;
- if (myMap2.count(temp))
- (*myMap2.find(temp)).second++;
- else myMap2.insert(pair <int, int>(temp, indx));
- }
- if (!flag)
- {
- string str;
- str = tmp;
- if (myMap.count(str))
- (*myMap.find(str)).second++;
- else myMap.insert(pair <string, int>(str, indx));
- }
- }
- in.close();
- ofstream out("output.txt");
- if (last != NULL)
- {
- if (myMap.empty())
- {
- out << "There is no words!";
- }
- else
- {
- int m = myMap2[last];
- for (map <string, int>::iterator iter = myMap.begin(); iter != myMap.end(); iter++)
- if (iter->second == m)
- {
- out << iter->first << " - " << iter->second << " entries" << endl;
- j++;
- }
- }
- if (j == 0)
- out << "There is no words that occur as many as the last word!";
- }
- else out << "Therer is no numbers!";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement