Home > Back-end >  Why ask bosses kangkang is 80 minutes, feel what all considered, CCF a problem
Why ask bosses kangkang is 80 minutes, feel what all considered, CCF a problem

Time:09-25

CCF on the topic
Item number: 201703-3
Item name: Markdown
Time limit: 1.0 s
Memory limit: 256.0 MB
Problem description
?? Markdown is a very popular lightweight markup language (lightweight markup language), widely used in the writing format of the document, for example the following text is written in the grammar of the Markdown:

?? These written in Markdown text, although itself is a pure text format, however, the reader can easily see the document structure, at the same time, there are many tools can automatically convert Markdown text to HTML or even a Word, PDF format, such as better typesetting effect, such as the above text is obtained by transforming the HTML code is as follows:

Subject requirements up to you to write a Markdown conversion tools, and complete the Markdown text to HTML code conversion work, simplicity, ontology defines the Markdown grammar rules and transformation rules described as follows:
Ontology: the block is one of the top structure, document the Markdown grammar have three block format, in the input, the adjacent two blocks are separated by one or more empty lines, delete all the output of the separated blocks of empty lines,
Paragraph: in general, continuous line, enter more constitute a paragraph, paragraph transformation rules is the first line by line in the paragraph first insert & lt; p> In the final at the end of the rows of insert & lt;/p> ,
Title: only a line, each title block by several # at the beginning, then one or more Spaces, then the title content, until the end of the line, the number of # determines the level of the title, transformation, # Heading into & lt; H1 & gt; HeadingUnordered list: unordered list consists of several rows, each row by the * at the beginning, then one or more Spaces, and then is the word list items, until the end of the line, transformation, in the most began to insert a line & lt; Ul> , the last insert a line & lt;/ul>; For each row, converting * Item & lt; Li> Item Ontology, the unordered list only one layer, there will not be indented,
Industry: for the contents of the block, there are two kinds of industry structure,
Emphasize: converting _Text_ & lt; Em> Text , insistence that there would be no nested, _ in each row number must be even, without continuous adjacent, pay attention to the front and back is not necessarily _Text_ space character,
Hyperlink: [Text] (Link) into & lt; A href="https://bbs.csdn.net/topics/Link" & gt; Text , hyperlink and emphasis can be nested, but each format can't more than one layer,
Input format
Input consists of several lines, said with a subject of Markdown syntax written documentation,
The output format
Output consists of several lines, according to the input of Markdown document into the HTML code,
The sample input
# Hello

Hello, world!
Sample output

Hello, world!


Review case size and agreed
Subject test point to satisfy the following conditions:
Subject each test point of the lines of the input data contains more than 100, the number of characters per line (including the newline character at the end of the line) no more than 100,
Besides newline, all characters are ASCII 32 to 126 printable characters,
Each line and will not be needed at the end of the line space character,
Input data in addition to the Markdown syntax required, the content will not appear in the #, *, _, [and], (,), & lt; , & gt; ,& These characters,
All test points are conform to the topic of Markdown syntax, your program does not need to consider syntax errors,
Each test point contains the grammar rules shown in the following table, which contains "tick" said, does not include the "x",

Test point numbered paragraph headings unordered list emphasizes the hyperlink
X x x x
1)X x x 3))
X x x 4))

5) XXX)Square root) x 6)
(7)))
X x 8)))

x x 9)))
10)))))-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

 # include & lt; Iostream> 
#include
#include
using namespace std;

String link_sub (string s, int fid, int mids, int eid)
{
String ans=s.s ubstr (fid, mid - fid);
String temp=s.s ubstr (mids + 1, eid - mid - 1);
Int l=temp. The size ();
for (int i=0; i{
If (temp [I]=='] '| | \ [I]==' (')
\ [I]=' ';
}
A string of text, the link;
Stringstream ss (temp);
Ss & gt;> The text & gt;> The link;
String STR="& lt; A href=https://bbs.csdn.net/"" + +" \ "link & gt;" + text + "& lt;/a> ";
Ans +=STR;
Return ans.
}

String str_link (string s)
{
String STR="";
Int fid=0, mid=0, len=s.s considering ();
for (int i=0; i{
[I] if (s=='[')
Mid=I;
Else if (s==[I] ') ')
{
STR +=link_sub (s, fid, mid, I);
Fid=I + 1;
}
}
If (fid!=len)
STR +=s.s ubstr (fid);
return str;
}

String str_em (string s)
{
Int len=s.s considering (), flag=0;
For (int I=len - 1; I & gt;=0; I -)
{
If (s==[I] '_')
{
Flag++;
If (flag % 2==1)
S=s.r eplace (I, 1, "& lt;/em>" );
The else
S=s.r eplace (I, 1, "& lt; Em>" );
}
}
Return s;
}

String func_str (string STR)
{
String s=str_link (STR);
Return str_em (s);
}

Void func_1 (string line, int len)
{
Int I, num=0;
For (I=0; i{
If (line [I]=='#')
num++;
Else if (line [I]!=' ')
break;
}
Cout & lt; <"& lt; H "& lt; String s=func_str (line. Substr (I));
Cout & lt; }

Void func_2 (string line, int len)
{
int i;
For (I=1; i{
If (line [I]!=' ')
break;
}
String s=func_str (line. Substr (I));
Cout & lt; <"& lt; Li>" " }

Void func_3 (string line)
{
The line=func_str (line);
Cout & lt; }

Int func_line (string line, int len, int flag)
{
If (len==0)
{
If (flag==2)
Cout & lt; <"& lt;/p>" Else if (flag==1)
Cout & lt; <"& lt;/ul>" Flag=0;
}
Else if (line [0]=='#')
{
Func_1 (line, len);
Flag=0;
}
Else if (line [0]=='*')
{
If (flag==0)
Cout & lt; <"& lt; Ul>" Func_2 (line, len);
Flag=1;
}
The else
{
If (flag==0)
Cout & lt; <"& lt; P> ";
The else
Cout & lt; Func_3 (line);
Flag=2;
}
return flag;
}

Int main ()
{
The string line;
Int flag=0;
//freopen (" 3. TXT ", "r", stdin);
While (getline (cin, line))
{
Int l=line. The size ();
Flag=func_line (line, l, flag);
nullnullnullnullnullnullnullnull

  • Related