题目不是很难
但 需要细心一些
cin.get()的功能是从输入流中读取走 字符
参考代码:
#include<iostream> #include<cstring> using namespace std; int main() { //freopen("data.in.txt","r",stdin); //freopen("data.out.txt","w",stdout); char c; while((c=cin.get())!=EOF) { if(c=='/') { char c1=cin.get(); if(c1=='/') { while((c1=cin.get())!='\n')//如果是//注释行的话 则找打最后的换行符 { } cout<<endl; //输出换行符 } else if(c1=='*')//如果是段注释 { while((c1=cin.get())) { if(c1=='*') { char c2=cin.get(); if(c2=='/')//找到*/ { break; } } } } else cout<<c<<c1;//小细节 如果没有出现注释 记得输出c,c1两个符号 } else cout<<c;// */后面的换行符会被赋给c 再输出 } return 0; }
0.0分
4 人评分