hpu 问题 D: 双斜杠注释

来源:互联网 发布:php强迫其它帐号下线 编辑:程序博客网 时间:2024/06/06 05:18

问题 D: 双斜杠注释

时间限制: 1 Sec 内存限制: 128 MB

题目描述

将C程序代码中的双斜杠注释去掉。

输入

输入数据中含有一些符合C++语法的代码行。

需要说明的是,为了方便编程,规定双斜杠注释内容不含有双引号。

源程序中没空行。

输出

输出不含有双斜杠注释的C++代码,除了注释代码之外,原语句行格式不变。

样例输入

//======================// simplest program//======================#includeusing namespace std;//----------------------int main(){  cout<<”hello world!\n”;}//---------------------

样例输出

#includeusing namespace std;int main(){  cout<<”hello world!\n”;}

思路:一组数据,输入字符串,然后分成单个字符存储,有利于寻找 ‘ / ’,最后一并输出结果;

#include<stdio.h>#include<string.h>char a[1000],b[1000][1000],c[1000][1000];int main(){int i=0,j,p=0,v=0;while(gets(a)!=NULL){for(j=0;j<strlen(a);j++){if(a[j]!='/')    b[p][i++]=a[j];else{break;}}if(i){strcpy(c[v++],b[p]);}i=0;p++;}for(j=0;j<v;j++){puts(c[j]);}return 0;}

1 0
原创粉丝点击