U
utab
Dear all,
I am trying to count the occurence of words in an input stream I can
keep my words in a vector<string> as below;
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <string>
#include <cstdlib>
using std::cout; using std::cin;
using std::vector; using std::endl;
using std::setprecision; using std::setw;
using std::max; using std::string;
int main(){
vector<string> str;
vector<string>::size_type sz;
string x;
while(cin >> x){
str.push_back(x);
}
sz=str.size();
for(vector<string>::size_type i=0; i!=sz; i++){
cout << str << endl;
}
return 0;
}
Now I think that sorting and finding the occurences are easier so sort
them alphabetically and then find the occurences. But the occurences
causing problems in the algorithms I try on paper. Please DO NOT USE
LISTS, VECTOR.ERASE(), ITERATORS IN THE PROBABLE SOLUTIONS.
Can someone give me any ideas on this?
Thx.
I am trying to count the occurence of words in an input stream I can
keep my words in a vector<string> as below;
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <string>
#include <cstdlib>
using std::cout; using std::cin;
using std::vector; using std::endl;
using std::setprecision; using std::setw;
using std::max; using std::string;
int main(){
vector<string> str;
vector<string>::size_type sz;
string x;
while(cin >> x){
str.push_back(x);
}
sz=str.size();
for(vector<string>::size_type i=0; i!=sz; i++){
cout << str << endl;
}
return 0;
}
Now I think that sorting and finding the occurences are easier so sort
them alphabetically and then find the occurences. But the occurences
causing problems in the algorithms I try on paper. Please DO NOT USE
LISTS, VECTOR.ERASE(), ITERATORS IN THE PROBABLE SOLUTIONS.
Can someone give me any ideas on this?
Thx.