样例输入
/*
This is a test
*/
#include <iostream>
using namespace std;
int main() // C/C++
{
cout << "Hello World!" << endl; /* cout is c++'s printf */ /* hello world */
return 0;
}
// end of file
样例输出
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
#pragma pack(4)
#define ES 0
#define EC 1
#define ED 2
#define EM 4
#define EME 8
int main()
{
string strfile = "1.cpp";
fstream file;
file.open(strfile);
string strcpp;
while (!file.eof()) {
char tmp[256];
file.getline(tmp, 256);
strcpp += tmp;
strcpp += "\n";
}
file.close();
string strout="";
int len = strcpp.length();
unsigned statue = ES;
for (int i = 0; i < len; i++) {
char c = strcpp[i];
switch (statue)
{
case ES:
if (c == '/')
statue = EC;
else
strout += c;
break;
case EC:
if (c == '*')
statue = EM;
else if (c == '/')
statue = ED;
else {
statue = ES;
strout += strcpp[i - 1];
strout += c;
}
break;
case ED:
if (c == '\n')
statue = ES;
break;
case EM:
if (c == '*')
statue = EME;
break;
case EME:
if (c == '/')
statue = ES;
else
statue = EM;
break;
default:
break;
}
}
cout << strout;
return 0;
}