zoukankan      html  css  js  c++  java
  • 【第19次CCF CSP认证】Markdown渲染器 (模拟)

    读题比较恶心,看到题目就不想写了(),手写了个逻辑理了半天。直接getline会有20分的点超时,手写读入过了,getchar大法好。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int maxn=10000010;
     4 int myget(char *b){
     5     char ch=getchar();
     6     if(ch==EOF)return -1; 
     7     int i=0;
     8     while(ch!='
    '&&ch!=EOF){
     9         *(b+i)=ch;++i;
    10         ch=getchar();
    11     }return i;
    12 }char a[21000000];
    13 int main(){
    14     //freopen("init2.txt","r",stdin);
    15     int n,typ=0,lin=1,cnt=0,now=0,lonf=0;
    16     int w;cin>>w;getchar(); 
    17     int num=0;
    18     // 段落 1,项目 2,无类型0 
    19     while((n=myget(a))!=-1){
    20         ++num;//cout<<num<<endl;
    21         int f=0;
    22         for(int i=0;i<n;++i){ if(a[i]!=' '){ f=1;break; } }
    23         //cout<<1<<' '<<lin<<' '<<cnt<<' '<<typ<<' '<<f<<endl;
    24         if(!f){ 
    25             lonf=1;
    26             continue;
    27         }
    28         if(a[0]=='*'&&a[1]==' '){
    29             if(lonf){
    30                 if(now==1){typ=0;cnt=0;lin+=2;}
    31                 if(cnt!=0){cnt=0;++lin;}
    32                 if(typ!=0){typ=0;++lin;} 
    33                 lonf=0;
    34             }
    35             if(typ==2){if(cnt!=0||now==1)++lin;}
    36             else if(typ==1){++lin; if(cnt!=0)++lin;}
    37             typ=2; cnt=0; now=0;
    38             int l=0,r=-1;
    39             for(int i=2;i<n;++i)if(a[i]!=' '){l=i;break;}
    40             for(int i=n-1;i>=2;--i)if(a[i]!=' '){r=i;break;}
    41             if(r==-1)now=1;
    42             for(int i=l;i<=r;++i){
    43                 if(cnt==0&&a[i]==' ')continue;
    44                 if(cnt==0)cnt=3;
    45                 ++cnt;
    46                 if(cnt==w){cnt=0;++lin;}
    47             }
    48         }
    49         else if(typ==2&&(!lonf)&&a[0]==' '&&a[1]==' '){
    50             int l=0,r=-1;
    51             for(int i=2;i<n;++i)if(a[i]!=' '){l=i;break;}
    52             for(int i=n-1;i>=2;--i)if(a[i]!=' '){r=i;break;}
    53             if(cnt==w-1){++lin;cnt=0;}
    54             else if(cnt!=0)++cnt;
    55             for(int i=l;i<=r;++i){
    56                 if(cnt==0&&a[i]==' ')continue;
    57                 if(cnt==0)cnt=3;
    58                 ++cnt;
    59                 if(cnt==w){cnt=0;++lin;}
    60             }
    61         }
    62         else{
    63             if(lonf){
    64                 if(now==1){typ=0;cnt=0;lin+=2;}
    65                 if(cnt!=0){cnt=0;++lin;}
    66                 if(typ!=0){typ=0;++lin;} 
    67                 lonf=0;
    68             }
    69             if(typ==1){
    70                 if(cnt==w-1){++lin;cnt=0;}
    71                 else if(cnt!=0)++cnt;
    72             }
    73             else if(typ==0)typ=1;
    74             else{ if(cnt!=0||now)++lin; ++lin;typ=1;cnt=0;}
    75             int l=0,r=-1;now=0;
    76             for(int i=0;i<n;++i)if(a[i]!=' '){l=i;break;}
    77             for(int i=n-1;i>=0;--i)if(a[i]!=' '){r=i;break;}
    78             for(int i=l;i<=r;++i){
    79                 if(cnt==0&&a[i]==' ')continue;
    80                 ++cnt;
    81                 if(cnt==w){cnt=0;++lin;}
    82             }
    83         } //cout<<2<<' '<<lin<<' '<<cnt<<' '<<typ<<endl;
    84     }
    85     if(cnt==0&&!now)--lin;
    86     cout<<lin<<endl;
    87     return 0;    
    88 }
    View Code
  • 相关阅读:
    Windows 8实例教程系列 开篇
    qt 开发发布于 windeploy.exe
    qt qoci 测试验证
    vmware vmx 版本不兼容
    qt oracle
    vc qt dll
    QOCIDriver unable to create environment
    qoci 编译完 放置位置 具体根据情况
    calling 'lastError' with incomplete return type 'QSqlError' qsqlquer
    Hbase 操作工具类
  • 原文地址:https://www.cnblogs.com/137shoebills/p/13615919.html
Copyright © 2011-2022 走看看