Reputation:
I have problem in string maniputation with C++.
The Rule: if the same 'word' is repeated from sentences or paragraph I want it to become an integer.
Example:
we prefer questions that can be answered, not just we discussed that.
1 prefer questions 2 can be answered, not just 1 discussed 2.
1 we
2 that
Upvotes: 0
Views: 491
Reputation: 30606
This type of problem is usually much easier to solve if you use an associative array to keep track of the words you have already seen. Try using an STL map for storing words you have seen already. It will take some work to get your logic set up correctly, but a map will definitely help with what you are trying to do.
Upvotes: 4
Reputation: 35460
Parsing:
For each word in the string
Check whether the word exists in map<WORD,Counter>
if the WORD is new the insert into the map with counter =0
otherwise increment the counter associated with word.
Output:(create new sentence)
For each word in the string
Lookup into the vector for counter value
if counter ==0 then insert WORD as it is
otherwise convert the counter to string and insert
Upvotes: 1
Reputation: 882146
This is the approach I would take (algorithms only, since it's homework).
Upvotes: 4