Sunday, June 28, 2020

Remove

In a certain area, there was a camp of polio drops team. They need to search for every baby in a particular area. They want to find the baby and take out the baby for polio drops. Help them to find the baby to avoid polio attacks. (remove the occurrence of the word "the" from the entered string).

Input Format:

The input is a string.

Text that is bold represents the input.

Output Format:

The output is a string.

Sample Input:

remove the occurrence of the word from entered string

Sample Output:

remove occurrence of word from entered string

SOLUTION:

#include<iostream>

using namespace std;

int main()

{

  string line;

  int count = 0;

  getline(cin,line);

  for(int i = 0; line[i] != '\0'; i++){

    if(line[i] == 't')

      if(line[i+1] == 'h')

        if(line[i+2] == 'e'){

          count = i;

          line.erase(line.begin() + count, line.begin() + count +4);

        }

  }

  for(int i = 0; line[i] != '\0'; i++){

      cout<<line[i];

  } 

}

No comments:

Post a Comment

horizontal ads