第十届福建省大学生程序设计竞赛 Problem H. Complier

2 篇文章 0 订阅
1 篇文章 0 订阅

Description

HIT_TOM gets high score in the course 《Compiling Principle》. So he wants to examine your knowledge of compilation principles.
He will give you some fragment, you need to remove the comments from it.
There are two cases of comments:

  1. Start with /* and end with */
  2. Start with //, extending to the end of the line

No characters are allowed to be deleted except for comments.

Input

A code fragment with several lines.
It is guaranteed that the number of characters is not exceeding 1000 for each line.
It is guaranteed that the total number of characters is not exceeding 100000.

Output

For each test case, you need to print all characters of the code except the commexts.

Sample

在这里插入图片描述

Hint

It is gurabteed that all characters are English characters. And to simplify the question, we ensure quotation marks ( ’ and " ) will not appear.
It is guaranteed that the test given can be complied by g++.
If you are confused with some situation, you can write you comments on your IDE (maybe codeblocks) to know what you should output.

#include <bits/stdc++.h>
using namespace std;
int main()
{
	char op;
	queue<char> q;
	while(~scanf("%c",&op)){
		q.push(op);
	}
	while(!q.empty()){
		if(q.front()=='/'){
			q.pop();
			if(q.front()=='/'||q.front()=='*'){
				while(q.front()!='\n'){
					q.pop();
				}
			}
			else printf("/");
		}
		else{
			printf("%c",q.front());
			q.pop();
		}
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值