zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    对象遍历 for in ,数组遍历for in 与 for of 的区别
    计算一个数组中key值相同的数量
    VUE的两种跳转push和replace对比区别
    微信公众号二次分享ios分享失败问题
    获得对象中的键或值
    第一个table根据checkbox选择tr,在另一个table中显示对应索引的tr(jq遍历的运用)
    checkbox 全选反选 获得所有的checkbox
    为什么jQuery要return this.each()?
    用jq代码写出一个轮播图。
    页面滚动到一定位置,两个div 朝中间运动。
  • 原文地址:https://www.cnblogs.com/CharlieWade/p/11474795.html
Copyright © 2011-2022 走看看