1215: 去掉双斜杠注释
时间限制: 1 Sec 内存限制: 128 MB题目描述
将C程序代码中的双斜杠注释去掉。 |
输入
输入数据中含有一些符合C++语法的代码行。需要说明的是,为了方便编程,规定双斜杠注释内容不含有双引号,源程序中没空行。
输出
输出不含有双斜杠注释的C++代码,除了注释代码之外,原语句行格式不变。
样例输入
//======================
// simplest program
//======================
#include
using namespace std;
//----------------------
int main(){
cout<<”hello world!\n”;
}//---------------------
样例输出
#include
using namespace std;
int main(){
cout<<”hello world!\n”;
}
提示
来源
CODE:(曾经写的---格式错误)
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
char c;
while((c=getchar())!=EOF)
{
if(c=='/'){
c=getchar();
if(c=='/'){
while(c!='\n'&&c!=EOF)
c=getchar();
}
else
cout<<'/'<<c;
// if(c=='\n')
// cout<<c;
}
else
cout<<c;
}
return 0;
}
CODE:
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int main()
{
char c[1005];
while(gets(c)){
bool flag=true;
for(int i=0;i<strlen(c);i++){
if(c[i]=='/'&&c[i+1]=='/')
break;
else{
flag=false;
cout<<c[i];
}
}
if(!flag)
cout<<endl;
}
return 0;
}