dristinct word in string c 2b 2b

Solutions on MaxInterview for dristinct word in string c 2b 2b by the best coders in the world

showing results for - "dristinct word in string c 2b 2b"
Finn
08 May 2020
1#include <iostream>
2#include <vector>
3
4using namespace std;
5
6int main()
7{
8    vector<string> words;
9    cout<<"Please Enter words(Press Ctrl+Z in the end)"<<endl;
10
11    string x; //Word Input
12    cin>>x;
13    words.push_back(x); //The first word
14    int ndw=1; //Number of distinct words
15
16    while(cin>>x) //Input new word
17    {
18        for(unsigned int counter = 0; counter!=words.size(); ++counter)
19        {
20            //Check if we already have this word in our list
21            if(x!=words[counter])
22            {
23                if(counter==words.size()-1)//We have reached the end of list
24                {
25                    words.push_back(x);
26                    ndw+=1;
27                }
28            }
29            else
30            {
31                //If there is a match, leave this word
32                break;
33            }
34        }
35    }
36    cout<<"number of distinct words are: "<<ndw;
37    return 0;
38}
39
similar questions
queries leading to this page
dristinct word in string c 2b 2b