• ccf 201703-3 Markdown


     ccf 201703-3 Markdown

      1 #include<iostream>
      2 #include<cstring>
      3 using namespace std;
      4 const int maxn = 100+5;
      5 char ans[maxn][maxn];
      6 
      7 void coutIn(char *a)
      8 {///进行行内文字的转换 
      9     for(int i=0;i<strlen(a);i++)
     10     {
     11         if(a[i] == '_')
     12         {//强调不会出现嵌套,每行中 `_` 的个数一定是偶数,
     13         //且不会连续相邻。注意 `_Text_` 的前后不一定是空格字符。
     14             cout<<"<em>";
     15             i++;
     16             int num = 0;
     17             char temp[maxn];
     18             while(a[i] != '_')
     19             {
     20                 temp[num++] = a[i];
     21                 i++;
     22             }
     23             temp[num] = '';
     24             i++;//忽略掉最后一个'_' 
     25             coutIn(temp);
     26             cout<<"</em>";
     27         }
     28         if(a[i] == '['){//处理超链接 
     29         //超级链接和强调可以相互嵌套,但每种格式不会超过一层。
     30             char temp[maxn];
     31             int num = 0;
     32             while(a[++i] != ']'){
     33                 temp[num++] = a[i];
     34             }
     35             temp[num] = '';
     36             cout<<"<a href="";
     37             while(a[i++] != '(');
     38             char temp2[maxn];
     39             int num2 = 0;
     40             while(a[i] != ')'){
     41                 temp2[num2++] = a[i];
     42                 i++;
     43             }
     44             temp2[num2] = '';
     45             i++;//去掉最后的')' 
     46             coutIn(temp2);
     47             cout<<"">" ;
     48             coutIn(temp);
     49             cout<<"</a>";
     50         }
     51         if(a[i] != '')
     52             cout<<a[i];
     53     }
     54 }
     55 void coutList(char *a)
     56 {
     57     cout<<"<li>";
     58     int space = 0;
     59     while(a[space] == ' ') space++;
     60     coutIn(a+space);
     61     cout<<"</li>"<<endl;
     62 }
     63 int main()
     64 {
     65     string str;
     66     int Count=0;
     67     
     68     while(getline(cin,str))
     69     {
     70         int len = str.length();
     71         for(int i=0;i<=len;i++){//将读入的行存储 
     72             if(i == len) ans[Count][i] = '';
     73             else ans[Count][i] = str[i];
     74         }
     75         Count++;
     76         ///注意'
    ’在字符数组中为'00' 
     77         ///空格 会保留 
     78      } 
     79      
     80      ///处理字符数组
     81      for(int i=0;i<Count;i++)
     82      {//逐行进行处理
     83          //标题行 
     84          if(ans[i][0] == '#') 
     85          {
     86              int temp = 1;
     87              while(ans[i][temp] == '#')
     88              {
     89                  temp++;
     90              }
     91              cout<<"<h"<<temp<<">";
     92                  ///输出行内字符
     93             int space = 0;
     94             while(ans[i][temp+space] == ' ') space++;
     95             //每个标题区块只有一行,由若干个 `#` 开头,
     96             //接着一个或多个空格,然后是标题内容,直到行末。
     97              coutIn(ans[i]+temp+space); 
     98              cout<<"</h"<<temp<<">"<<endl;
     99              continue;
    100          }
    101          else if(ans[i][0] == '')//空格行 
    102          {//输出时删除所有分隔区块的空行 
    103              continue;
    104          }
    105          else if(ans[i][0] == '*'){///处理列表 
    106              cout<<"<ul>"<<endl;
    107              coutList(ans[i]+1);//输出第一行列表
    108              //每行由 `*` 开头,接着一个或多个空格,然后是列表项目的文字,直到行末。
    109             while(ans[i+1][0] == '*')
    110             {
    111                 coutList(ans[++i]+1);
    112              } 
    113              cout<<"</ul>"<<endl;
    114          }
    115          else{
    116              cout<<"<p>";
    117              coutIn(ans[i]);
    118              while(ans[i+1][0] != ''){
    119                  cout<<endl;
    120                  coutIn(ans[++i]);
    121              }
    122              cout<<"</p>"<<endl;
    123          } 
    124           
    125       }
    126       /*
    127      for(int i=0;i<Count;i++)
    128          printf("%s",ans[i]); 
    129     */
    130     return 0;
    131 }

  • 相关阅读:
    安装和强行卸载fuse
    Elasticsearch snapshot 备份的使用方法 【备忘】
    MYSQL数据仓库infobright【备忘】
    Tomcat8 启动慢 Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [53,161] milliseconds
    python爬虫实例
    JDK1.8 JVM参数配置
    QQ登录用到的URL
    CAS5.3.X 配置备忘
    Nexus3忘记admin密码时的解决办法
    CentOS7利用systemctl添加自定义系统服务
  • 原文地址:https://www.cnblogs.com/yxh-amysear/p/8522370.html
Copyright © 2020-2023  润新知