swustoj0054-Software Bugs

The biggest problem for all software developers are bugs. You definitely know the situation when a user calls to say ”I’ve found a bug in your program”. Once you have found and removed the bug, another one appears immediately. It is a hard and never-ending process.

Recently, there appeared a promising open-source initiative called “bug-preprocessor”. The bugpreprocessor is a program able to find all bugs in your source code and mark them, so they are relatively easy to be removed. Your task is to write a program that will remove all marked bugs from the preprocessed source code.

enter

 
  

The input contains a text representing the preprocessed source code, an unspecified number of lines of text, some of them may be empty. Bugs are represented by a case-sensitive string “BUG”. The text is terminated by the end of file. No line in the input will be longer than 100 characters.

output

 
  

Your program must remove all of the bugs from the input and print a text that does not contain any BUG strings. Nothing else than bugs may be removed, not even spaces.

sample input

print "No bugs here..."
void hello() {
BUGBUG
printfBUG("Hello, world!\n");
}
wriBUGBUGtelBUGn("Hello B-U-G");

Sample output

print "No bugs here..."
void hello() {

printf("Hello, world!\n");
}
writeln("Hello B-U-G");
The meaning of the question: delete the BUG substring in the string until there is no BUG substring.

Idea: Directly call library functions in one step.



#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<string>
using namespace std;

intmain()
{
	string str;
	while (getline(cin,str,'\n')) {
		int t = str.find("BUG");
		while (t >= 0 ) {
			str.erase(t, 3);
			t = str.find("BUG");
		}
		cout << str << endl;
	}

	return 0;
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325668722&siteId=291194637