Mark-up
Mark-up |
Mark-up languages are computer languages that assist in the formattingof text files. Specialkeywords are used to mark the text to allow control of fonts, pagestyles, paragraph styles, etc.TeX, troff, and HTML are examples of mark-up languages.
Spell checking can be difficult to adapt to these special texts.In general, special processors orspell checkers must be created in order to accommodate mark-uplanguages. A special processorwould recognize the mark-up language and strip it from the textso that the ``plain'' text couldthen be processed by a spell checker. For this problem, you are towrite such a processor for a smallmark-up language so that the output of your program will be theplain text without the mark-ups.
The mark-up language to consider is one which allows the modificationof fonts within the text.Each markup command will be preceded by a\
character.If the letter following the
\
characteris not a recognized command from the table below then the characterfollowing the\
is printed aspart of the plain text. For instance, the mark-up
\\
canbe used to print a single \
.
- toggle bold font on/off (default state is off)
- toggle italics font on/off (default state is off)
- set font size; the s is immediately followed byan optional number; if the number ismissing then the command will restore the previous size
- toggle processing of mark-ups on/off; if processingis toggled off then mark-ups areconsidered to be literal text (default state is on)




The number following the SPMamp
& command can have a decimal pointso 12, 9.5, 11., and .5 should all be recognized as valid numbers.
Input and Output
The input file will be plain text containing mark-ups from the languageabove. At the start, processing of mark-ups should be on.The file should be processed until the end-of-file is encountered.
Sample Input
\s18.\bMARKUP sample\b\s \*For bold statements use the \b command.\* If you wish to \iemphasize\i something use the \\i command. For titles use \s14BIG\s font sizes, 14 points usually works well. Remember that all of the commands toggle except for the \\s command.
Sample Output
MARKUP sample For bold statements use the \b command. If you wish to emphasize something use the \i command. For titles use BIG font sizes, 14 points usually works well. Remember that all of the commands toggle except for the \s command.
刚开始,输出一个换行符提交Wrong answer
#include <cstdio>
#include <string>
#include <cctype>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endif
string s;
char ch, prev;
bool on = true;
bool first = true;
prev = -1;
while ((ch = getchar()) != EOF) {
if (on) {
if (prev == '\\' && ch == 's') {
while ((ch = getchar()) != EOF) {
if (first && ch == '.') {
first = false;
continue;
}
if (!isdigit(ch) || (!first && ch == '.')) break;
}
first = true;
//if (ch == '.') ch = getchar();
if (ch == EOF) break;
prev = ch;
} else if (prev == '\\' && ch == 'b') {
ch = getchar();
if (ch == EOF) break;
prev = ch;
} else if (prev == '\\' && ch == '*') {
on = false;
ch = getchar();
if (ch == EOF) break;
prev = ch;
} else if (prev == '\\' && ch == 'i') {
ch = getchar();
if (ch == EOF) break;
prev = ch;
} else if (prev == '\\') {
s += ch;
ch = getchar();
if (ch == EOF) break;
prev = ch;
}else {
if (prev != -1) s += prev;
prev = ch;
}
} else {
if (prev == '\\' && ch == '*') {
on = true;
ch = getchar();
if (ch == EOF) break;
prev = ch;
} else {
s += prev;
prev = ch;
}
}
}
if (prev != -1) s += prev;
printf("%s", s.c_str());
return 0;
}