CCF 201703-3 Markdown

http://118.190.20.162/view.page?gpid=T55
按题意写呗,把区和行的转换分开

#include
#include
using namespace std;
string AA(string str)
{
    string x;
    int f = 0;
    int le = str.size();
    for (int i = 0; i < le; ) {
        if (str[i] == '_') {
            if (f) { x+=""; f = 0; }
            else { x+=""; f = 1; }
            ++i; continue;
        }
        if (str[i] == '[') {
            int j = i ;
            while (str[j++] != ']');
            j--;
            int k = j + 1;
            while (str[k++] != ')');
            k--;
            x += "+AA(string(str,j+2,k-j-2))
                +"\">"+AA(string(str, i + 1, j - i-1))+"";
            i = k + 1; continue;
        }
        x += str[i++];
    }
    return x;
}
int main()
{
    cin.clear();
    string s[200];
    int len = 0;
    int flag = 0;
    while (getline(cin, s[len++]));
    for (int i = 0; i <= len; )
    {
        if (s[i][0] == '#') {
            int j = 0;
            while (s[i][++j] == '#');
            int k = j - 1;
            while (s[i][++k] == ' ');
            cout << " << j << ">" << AA(string(s[i], k, 100)) << " << j << ">" << endl;
            ++i; continue;
        }
        if (s[i][0] == '*') {

            int j = 0;
            if (flag != 2) cout << "
    " << endl; flag = 2; while (s[i][++j] == ' '); cout << "
  • " << AA(string(s[i], j, 100)) << "
  • "
    << endl; ++i; continue; } if (s[i] == "") { if (flag == 2) cout << "
"
<< endl; flag = 0; ++i; continue; } if (flag == 0) cout << "

"; flag = 1; cout << AA(s[i]); if (s[++i] == "") { cout << "

"
<< endl; } else cout << endl; } return 0; }

你可能感兴趣的:(CCF 201703-3 Markdown)