题目链接:点击这里
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
char c;
char pre = 'x';
bool dan = false, duo = false;
while((c = cin.get()) != EOF)
{
if(dan) //进入单行注释
{
if(c=='\n') //遇到换行结束
{
cout<<endl;
dan = false;
}
continue;
}
if(duo) //进入多行注释
{
if(pre == '*' && c == '/') duo = false; //遇到*/结束
else pre = c; //此时需要记录前一个字符作为判断
continue;
}
if(c == '/')
{
c = getchar();
if(c == '/') dan = true;
else if(c == '*') duo = true;
else cout<<"/"<<c;
}
else
cout<<c;
}
return 0;
}