FZU 1558 Software Bugs

 

Software Bugs
Time Limit:1s Memory limit:32M
Accepted Submit:141 Total Submit:250

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.

Input

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");
wriBBBUGUGGteln("Hello B-UG");

Sample Output

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

  printf("Hello, world!/n");
}
writeln("Hello B-U-G");
wriBGteln("Hello B-UG");

Original: FOJ月赛-2007年12月

 

解题:

        功能的实现封装在函数里面,要注意引号里面的BUG不要去掉。每次循环检查BUG,然后去掉BUG之后,要把循环重置,重新开始消除BUG,才能把隐藏在BUG中的BUG去掉。

#include <iostream> #include <string> using namespace std; void dele(char b[],int n,int m) { for(int i=m;i<n;i++) b[i]=b[i+1]; } void findBug(char a[],int n) { int flag=0; for(int i=0;i<n;i++) { if(a[i]=='"') { if(i!=0) { if(a[i]-1=='//') continue; } flag++; if(flag==2) flag=0; continue; } if(a[i]=='B' && i<n-2) { if(a[i+1]=='U' && a[i+2]=='G' && flag==0) { dele(a,n,i); dele(a,n-1,i); dele(a,n-2,i); i=-1; //将i置为开头,下次循环将加1,所以这里设为-1; } } } } int main() { int lines=100; char s[101]; memset(s,'/0',sizeof(s)); while(cin.getline(s,101)) { findBug(s,strlen(s)); cout<<s<<endl; } return 0; }

你可能感兴趣的:(String,user,ini,input,bugs)