刚开始只有60分 后来仔细读了下题发现#和*后面可能有多个空格.....然后就用流处理了下....就只有40分了...估计是后面存在空格...........后来发现超链接加粗那些存在嵌套关系,每一层都有,但是改了后也只有90
//90fen
#include<iostream>
#include<sstream>
#include<algorithm>
#include<string.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int N = 100+5;
vector<string> v;
void SuperLink(string &s) {
//_和[] ()
int ml, mr, sl, sr;
string s1, s2;
ml = s.find('[');
mr = s.find(']');
sl = s.find('(');
sr = s.find(')');
if(ml != string::npos && mr != string::npos && sl != string::npos && sr != string::npos) {
s1 = s.substr(ml+1, mr-ml-1);
s2 = "<a href=\""+s.substr(sl+1, sr-sl-1)+"\">"+s1+"</a>";
s = s.replace(ml, sr-ml+1, s2);
}
}
void OutOrder(string&s) {
string pa="_";
int pos = 0, num = 0;
while((pos = s.find(pa, pos))!=string::npos) {
num++;
if(num%2)
s.replace(pos, 1, "<em>");
else s.replace(pos, 1, "</em>");
pos++;
}
}
int main() {
string s, pre="";
while(getline(cin, s)) {
// cout << s.size() << endl;
if(s == "") {
pre = s;
continue;
} else if(s[0] == '#') {
// cout << "#" << endl;
int cnt = 0;
while(s[cnt] == '#') {
cnt++;
}
// sprintf(tmp, "<h%d>%s</h%d>", cnt, s.substr(cnt+1).c_str(), cnt);//有错误
string tmp = "0";
char t = cnt+'0';
tmp[0] = t;
while(s[cnt] == ' ') {
cnt++;
}
s = s.substr(cnt);
OutOrder(s);
SuperLink(s);
string stm = "<h"+tmp+">"+s+"</h"+tmp+">";
v.push_back(stm);
} else if(s[0] == '*') {
if(pre.size() && v.size() && v.back() == "</ul>")
v.pop_back();
else
v.push_back("<ul>");
int cnt = 2;
while(s[cnt] == ' ') {
cnt++;
}
s = s.substr(cnt);
OutOrder(s);
SuperLink(s);
string tmp = "<li>"+s+"</li>";
v.push_back(tmp);
v.push_back("</ul>");
} else { //段落
bool flag = true;
if(v.size()) {
string tmp = v.back();
int len = tmp.length();
// cout << tmp.substr(len-4, 4) << endl;
if(pre.size() && tmp.substr(len-4, 4) == "</p>") {
v.back() = tmp.erase(len-4, 4);
flag = false;
}
}
OutOrder(s);
SuperLink(s);
if(flag)
s = "<p>"+s+"</p>";
else s += "</p>";
v.push_back(s);
}
pre = s;
}
for(int i=0; i<v.size(); i++) {
cout << v[i] << endl;
}
return 0;
}
/*
# Heading
## Sub-heading
paragraph are separated
by a blank line.
Text attribute _italic_.
Bullet list:
* apples
* oranges
* pears
A [link](http://example.com).
*/
/*
# HeadingA [link](http://example.com).
## Sub-heading
paragraph are separated
by a blank line.
Text attribute .[_italic_link](http_italic_://example.com)
Bullet list:
* apples[li(http://example.com)nk]
* oranges
* pears
*/
//60分
#include<iostream>
#include<sstream>
#include<algorithm>
#include<string.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int N = 100+5;
vector<string> v;
int main() {
string s, pre="";
while(getline(cin, s)) {
// cout << s.size() << endl;
if(s == "") {
pre = s;
continue;
} else if(s[0] == '#') {
// cout << "#" << endl;
int cnt = 0;
while(s[cnt] == '#') {
cnt++;
}
// sprintf(tmp, "<h%d>%s</h%d>", cnt, s.substr(cnt+1).c_str(), cnt);//有错误
string tmp = "0";
char t = cnt+'0';
tmp[0] = t;
string stm = "<h"+tmp+">"+s.substr(cnt+1)+"</h"+tmp+">";
v.push_back(stm);
} else if(s[0] == '*') {
if(pre.size() && v.size() && v.back() == "</ul>")
v.pop_back();
else
v.push_back("<ul>");
s = s.substr(2);
string tmp = "<li>"+s+"</li>";
v.push_back(tmp);
v.push_back("</ul>");
} else { //段落
bool flag = true;
if(v.size()) {
string tmp = v.back();
int len = tmp.length();
// cout << tmp.substr(len-4, 4) << endl;
if(pre.size() && tmp.substr(len-4, 4) == "</p>") {
v.back() = tmp.erase(len-4, 4);
flag = false;
}
}
//_和[] ()
int ml, mr, sl, sr;
string s1, s2;
ml = s.find('[');
mr = s.find(']');
sl = s.find('(');
sr = s.find(')');
if(ml != string::npos && mr != string::npos && sl != string::npos && sr != string::npos&& ml<mr&&mr<sl&&sl<sr) {
s1 = s.substr(ml+1, mr-ml-1);
s2 = "<a href=\""+s.substr(sl+1, sr-sl-1)+"\">"+s1+"</a>";
s = s.replace(ml, sr-ml+1, s2);
}
string pa="_";
int pos = 0, num = 0;
while((pos = s.find(pa, pos))!=string::npos) {
num++;
if(num%2)
s.replace(pos, 1, "<em>");
else s.replace(pos, 1, "</em>");
pos++;
}
if(flag)
s = "<p>"+s+"</p>";
else s += "</p>";
v.push_back(s);
}
pre = s;
}
for(int i=0; i<v.size(); i++) {
cout << v[i] << endl;
}
return 0;
}
/*
# Heading
## Sub-heading
paragraph are separated
by a blank line.
Text attribute _italic_.
Bullet list:
* apples
* oranges
* pears
A [link](http://example.com).
*/
/*
# Heading
## Sub-heading
paragraph are separated
by a blank line.
Text attribute _italic_.
A [link](http://example.com).
Bullet list:
* apples
* oranges
* pears
*/
//40
#include<iostream>
#include<sstream>
#include<algorithm>
#include<string.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int N = 100+5;
vector<string> v;
int main() {
string s, pre="";
while(getline(cin, s)) {
// cout << s.size() << endl;
if(s == "") {
pre = s;
continue;
} else if(s[0] == '#') {
// cout << "#" << endl;
int cnt = 0;
stringstream ss(s);
string s1;
ss >> s1;
cnt = s1.length();
ss >> s;
// sprintf(tmp, "<h%d>%s</h%d>", cnt, s.substr(cnt+1).c_str(), cnt);//有错误
string tmp = "0";
char t = cnt+'0';
tmp[0] = t;
string stm = "<h"+tmp+">"+s+"</h"+tmp+">";
v.push_back(stm);
} else if(s[0] == '*') {
if(v.size() && v.back() == "</ul>")
v.pop_back();
else
v.push_back("<ul>");
stringstream ss(s);
ss >> s;
ss >> s;
// s = s.substr(2);
string tmp = "<li>"+s+"</li>";
v.push_back(tmp);
v.push_back("</ul>");
} else { //段落
bool flag = true;
if(v.size()) {
string tmp = v.back();
int len = tmp.length();
// cout << tmp.substr(len-4, 4) << endl;
if(pre.size() && tmp.substr(len-4, 4) == "</p>") {
v.back() = tmp.erase(len-4, 4);
flag = false;
}
}
//_和[] ()
int ml, mr, sl, sr;
string s1, s2;
ml = s.find('[');
mr = s.find(']');
sl = s.find('(');
sr = s.find(')');
if(ml != string::npos && mr != string::npos && sl != string::npos && sr != string::npos&& ml<mr&&mr<sl&&sl<sr) {
s1 = s.substr(ml+1, mr-ml-1);
s2 = "<a href=\""+s.substr(sl+1, sr-sl-1)+"\">"+s1+"</a>";
s = s.replace(ml, sr-ml+1, s2);
}
string pa="_";
int pos = 0, num = 0;
while((pos = s.find(pa, pos))!=string::npos) {
num++;
if(num%2)
s.replace(pos, 1, "<em>");
else s.replace(pos, 1, "</em>");
pos++;
}
if(flag)
s = "<p>"+s+"</p>";
else s += "</p>";
v.push_back(s);
}
pre = s;
}
for(int i=0; i<v.size(); i++) {
cout << v[i] << endl;
}
return 0;
}
/*
# Heading
## Sub-heading
paragraph are separated
by a blank line.
Text attribute _italic_.
A [link](http://example.com).
Bullet list:
* apples
* oranges
* pears
*/