In article < .com>,
"utab" <> wrote:
> How to control that is not that easier to sort and apply.
No, it isn't easer.
> I am now
> trying that but still problems with the algoritm I have created two
> more vectors. One holding the words and the other holding the repeat
> times corresponding to the words. Code is wrong but I am sending it
> anyway. I think you will understand what I try to do
You need to start smaller, and work your way up. Paste the code below
into your cpp file (overwrite what you have) and then run the program.
What you are supposed to see is "working" what you will actually see is
some error message. Put code in the "insert your code here" spot and
keep running the program until you can get "working" to appear on the
screen. Once you do that, I'll take you to the next step.
@begin code
#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;
void count_words( const vector<string>& S, vector<string>& ss,
vector<int>& nn )
{
// insert code here
}
int main() {
{
vector<string> in;
in.push_back( "word" );
vector<string> str;
vector<int> count;
count_words( in, str, count );
assert( str.size() == 1 );
assert( count.size() == 1 );
assert( str[0] == "word" );
assert( count[0] == 1 );
}
{
vector<string> in;
in.push_back( "word" );
in.push_back( "big" );
vector<string> str;
vector<int> count;
count_words( in, str, count );
assert( str.size() == 2 );
assert( count.size() == 2 );
assert( str[0] == "word" );
assert( count[0] == 1 );
assert( str[1] == "big" );
assert( count[1] == 1 );
}
cout << "working";
}
@end code
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
|