zoukankan      html  css  js  c++  java
  • 201703-3 markdown

    实现

    #include <iostream>
    #include <string>
    #include <cstring>
    
    using namespace std;
    
    string line;
    int line_index = 0;
    
    void handle_link() {
        ++line_index;
    
        char text[255]; int text_index = 0;
        while (line[line_index] != ']') {
            text[text_index++] = line[line_index++];
        }
    
        line_index+=2;
    
        char link[255]; int link_index = 0;
        while (line[line_index] != ')') {
            link[link_index++] = line[line_index++];
        }
        ++line_index;
    
    
        cout << "<a href="" ; 
        for (int i = 0;i < link_index;++i) {
            if (link[i] != '_') {
                cout << link[i];
            } else {
                cout << "<em>";
                ++i;
                while (link[i] != '_') {
                    cout << link[i++];
                }
                cout << "</em>";
            }
        }
        
        cout << "">";
    
        for (int i = 0;i < text_index;++i) {
            if (text[i] != '_') {
                cout << text[i];
            } else {
                cout << "<em>";
                ++i;
                while (text[i] != '_') {
                    cout << text[i++];
                }
                cout << "</em>";
            }
        }
        cout << "</a>";
    }
    
    void handle_emp() {
        ++line_index;
        cout << "<em>";
    
        while (line_index < line.size()) {
            switch (line[line_index])
            {
                case '_':
                    ++line_index;
                    cout << "</em>";
                    return;
                case '[':
                    handle_link();
                    break;
                default:
                    cout << line[line_index++];
                    break;
            }
        }
    }
    
    void handle_line() {
    	while (line_index < line.size()) {
    	    switch (line[line_index])
    	    {
    	        case '_':
    	            handle_emp();
    	            break;
    	        case '[':
    	            handle_link();
    	            break;
    	        default:
    	            if (line_index == line.size()) {
    	                return;
    	            } else {
    	                cout << line[line_index++];
    	            }
    	            break;
    	        if (line_index == line.size()) { 
    	            return;
    	        }
    	    }
    	
    	}
    }
    
    int main() {
        
        while (getline(cin,line)){ 
    
            line_index = 0;
    
            handle_begin:;  
    
            if (line.empty()) {
                continue;
            } else if (line[0] == '#') {
                int sharp_cnt = 0;
                while(line[line_index++] == '#') {
                    sharp_cnt+=1;
                }
                cout << "<h" << sharp_cnt << ">";
    
                while (isspace(line[line_index])) {
                    ++line_index;
                }
                handle_line();
                cout << "</h" << sharp_cnt << ">" << endl;
            } else if (line[0] == '*') {
                cout << "<ul>" << endl;
    
                handle_list:;
    
                ++line_index;
                while(isspace(line[line_index])) {
                    ++line_index;
                }
    
                cout << "<li>";
                handle_line();
                cout << "</li>" << endl;
    
                if (getline(cin,line)) {
                    line_index = 0;
                    if (line.empty()||line[0] != '*') {
                        cout << "</ul>" << endl;
                        goto handle_begin;
                    } else {
                        goto handle_list;
                    }
                }
                cout << "</ul>";
                break;
            } else {
                cout << "<p>";
                
                handle_content:;
    
                handle_line();
    
                if (getline(cin,line)) {
                    line_index = 0;
                    if (line.empty() || line[0] == '*' || line[0] == '#') {
                        cout << "</p>" << endl;
                        goto handle_begin;
                    } else {
                        cout << endl;
                        goto handle_content;
                    }
                }
                cout << "</p>";
                break;
            }
    
        }
    }
    
    
  • 相关阅读:
    比服务器的问题
    android studio adb.exe已停止工作(全面成功版 进程的查询和开启)
    安卓学习123
    java eclipse 安卓环境配置
    host访问goole
    Android studio自带的sample例子
    马士兵2string buffuer
    tomcat内存溢出,设置
    spring mvc 学习笔记【1】---前言
    dbutils报错:com.microsoft.sqlserver.jdbc.SQLServerException: 无法识别元数据的表
  • 原文地址:https://www.cnblogs.com/amonqsq/p/13610991.html
Copyright © 2011-2022 走看看