Created
September 28, 2015 10:15
-
-
Save ogroleg/5f484b618138dfeeab37 to your computer and use it in GitHub Desktop.
map multimap lab oop work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <fstream> | |
#include <iostream> | |
#include <sstream> | |
#include <string> | |
#include <map> | |
#include <iterator> | |
#include <algorithm> | |
using namespace std; | |
typedef map<string, int> word_count_list; | |
typedef multimap<int, string> word_count_list2; | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
word_count_list2 word_count2; | |
ifstream file("/home/oleg/untitled2/input.txt"); | |
string word; | |
while (file >> word) | |
{ | |
int index; | |
while ((index = word.find_first_of(".,!?\\;-*+")) != string::npos) | |
{ | |
word.erase(index, 1); | |
} | |
bool found = false; | |
for (word_count_list2::iterator iter=word_count2.begin(); iter!=word_count2.end(); iter++){ | |
if(iter->second==word) | |
{ | |
word_count2.erase(iter); | |
word_count2.insert(make_pair(iter->first+1,word)); | |
found = true; | |
break; | |
} | |
} | |
if (!found) word_count2.insert(make_pair(1, word)); | |
} | |
word_count_list2::const_iterator current(word_count2.begin()); | |
while (current != word_count2.end()) | |
{ | |
cout <<current->first<< " " << current->second << endl; | |
++current; | |
} | |
/*word_count_list word_count; | |
ifstream file("/home/oleg/untitled2/input.txt"); | |
string word; | |
while (file >> word) | |
{ | |
int index; | |
while ((index = word.find_first_of(".,!?\\;-*+")) != string::npos) | |
{ | |
word.erase(index, 1); | |
} | |
++word_count[word]; | |
} | |
word_count_list::const_iterator current(word_count.begin()); | |
while (current != word_count.end()) | |
{ | |
cout <<current->first<< " " << current->second << endl; | |
++current; | |
}*/ | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment