• 2019福建省赛—Complier(简单字符串处理)


    Complier

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

    题目描述

    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 code 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.
     

    输入

    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.
     

    输出

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

    样例输入

    int main() {
        return 0; // this is a comment
    }
    

    样例输出

    int main() {
        return 0;
    }

    提示

    It is guaranteed 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 cases 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.

    虽然是道水题,可是自己还是写了好久,可能是我太菜了,写个博客记录一下吧

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 const int maxn=1e5+7;
     5 char str[maxn];
     6 int main()
     7 {
     8     ll x=1;
     9     /*x*/x*=x;/*x*/x*=x;/*x*/x*=x;/*x*/x*=x;/*x*/x*=x;/*x*/x*=x;/*x*/x=8*2;/*x*/
    10     /*123/*//*/**/
    11     /*123/*//*/*123*/
    12     /*123/*//*123/*123*/
    13     /*123/*123//*123/*123*/
    14 
    15     /*
    16     int main() {
    17         return 0; // this is a comment
    18     }
    19     */
    20     //样例测试用
    21 
    22     int flag=0;
    23     while(gets(str))
    24     {
    25         int len=strlen(str);
    26         int i=0;
    27         while(i<len)
    28         {
    29             if(flag==0&&i<len-1&&str[i]=='/'&&str[i+1]=='/')
    30             {
    31                 str[i]='1',str[i+1]='1';
    32                 flag=1;
    33                 i+=2;
    34             }
    35             if(flag==0&&i<len-1&&str[i]=='/'&&str[i+1]=='*')
    36             {
    37                 str[i]='1',str[i+1]='1';
    38                 flag=2;
    39                 i+=2;
    40             }
    41             if(i<=len-1&&flag==0)putchar(str[i]),++i;
    42             if(flag==2&&i<len-1&&str[i]=='*'&&str[i+1]=='/')
    43             {
    44                 str[i]='1',str[i+1]='1';
    45                 flag=0;
    46                 i+=2;
    47             }
    48             if(flag!=0)++i;
    49         }
    50         if(flag==1||flag==0)
    51         {
    52             flag=0;
    53             puts("");
    54         }
    55     }
    56     return 0;
    57 }
  • 相关阅读:
    hdu 5645 DZY Loves Balls
    idea2016的使用心得 --- 太棒了
    20170410 --- Linux备课资料 --- 压缩与解压缩
    20170410 --- Linux备课资料 --- vim的使用
    mysql20170410练习代码+笔记
    你说你有多坑?----超市项目错误总结
    说好的不熬夜呢???!!!! -- 超市项目
    那些年搞不懂的高深术语——依赖倒置•控制反转•依赖注入•面向接口编程
    今天思考一个问题 --- 自己的强项是什么??
    sleep()和wait()的区别 --- 快入睡了,突然想起一个知识点,搞完就睡
  • 原文地址:https://www.cnblogs.com/CharlieWade/p/11474795.html
Copyright © 2020-2023  润新知