Skip to content

Commit d1f8127

Browse files
authored
Create Readme.md
1 parent cd99779 commit d1f8127

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### 722.Remove-Comments
2+
3+
令s代表待输出的一行。此题考虑这么几个问题:
4+
5+
1. 遇到"//"怎么办? 这一行的字符就直接跳过,直接将s加入result(注意,此时必须是非comment模式)
6+
2. 遇到"/*"怎么办? 进入了comment模式
7+
3. 遇到"*/"怎么办? comment模式结束,可以将s加入result
8+
4. 普通字符?将字符加入s
9+
5. 始终在comment模式里? 那么继续遍历字符
10+
6. 如果到了行结束,且不是comment模式,那么就可以将s加入result
11+
12+
要能够和谐地处理以上这几种情况,我们可以设置一个bool变量comment。
13+
14+
1. comment off && "//"怎么办? 直接挑出该行
15+
2. comment off && "/*"怎么办? 进入了comment模式
16+
3. comment on && "*/"怎么办? 退出comment模式
17+
4. comment off && 普通字符?将字符加入s
18+
5. comment on && 普通字符?忽略该字符
19+
6. 到了行结束,&& comment off:那么就可以将s加入result,清空s

0 commit comments

Comments
 (0)