Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C++ where you keep reading strings from the input, and then:

ID: 3790729 • Letter: W

Question

Write a program in C++ where you keep reading strings from the input, and then: if the number of characters is three or less, you will store the string in a vector; if the number of characters is more than three, you will first remove from it all occurrences of the strings stored in your vector, and then you will output the string. Stop when string "quit" is read. String "quit" should not be processed.

Sample Input:
air
de
op
cat
desktop
airplane
in
oo
catintheroof
quit

Sample Output:
skt
plane
therf

Explanation / Answer

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
vector<string> v;

string s;
cin >> s;

while(s != "quit")
{
if (s.length() <= 3)
{
if (find(v.begin(), v.end(), s) == v.end()) {
v.push_back(s);
}
}
else
{
for(int i = 0; i != v.size(); i++) {
int start = s.find(v[i]);
if (start != -1)
s.erase(start, v[i].length());
}

cout << s << endl;
}
cin >> s;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote