1 Write a program where you will have a vector V where each
1. Write a program where you will have a vector V where each entry is a pointer to a vector of strings. This means that each entry in V points to a vector of strings. Your program will then read input strings. For each string, if the number of characters in the string is N, then add it to the string vector in entry V[N]. Be sure to allocate the string vector in each entry as needed. The input string will have a maximum of 10 characters so you can initialize V with 10 entries. Do not add repeated entries. Stop when string quit is read. String quit should not be processed. Then output the contents of each V entry in order from V[0] to V[10], separated by spaces within the same V entry and by a new line when switching to the next entry. Skip empty entries.
Solution
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
vector<vector<string> > V(11);
string str;
for (int i = 0; i < V.size(); ++i){
V[i] = {};
}
int flag = 0;
while (true){
cin >> str;
if (str == \"quit\" || str.size() > 10){
break;
}
flag = 0;
if (find(V[str.size()].begin(), V[str.size()].end(), str) != V[str.size()].end()){
flag = 1;
}
if (flag == 0){
V[str.size()].push_back(str);
}
}
for (int i = 0; i < V.size(); ++i){
for (int j = 0; j < V[i].size(); ++j){
cout << V[i][j] << \" \";
}
cout << endl;
}
return 0;
}