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 }
  • 相关阅读:
    win10+Linux双系统安装及一些配置问题
    第3讲--3.1旋转矩阵
    【读诗】宣州谢朓楼饯别校书叔云
    【2】python:end=' '
    如何与国外导师联系
    PointNet
    点云深度学习
    ES6常用方法
    监听滚动条、上下联动
    echarts 左右滚动
  • 原文地址:https://www.cnblogs.com/CharlieWade/p/11474795.html
Copyright © 2011-2022 走看看