24h購物| | PChome| 登入
2013-06-04 08:54:56| 人氣1,551| 回應0 | 上一篇 | 下一篇

[UVA] 391 - Mark-up

推薦 0 收藏 0 轉貼0 訂閱站台


 Mark-up 

Mark-up languages are computer languages that assist in the formatting of text files. Special keywords are used to mark the text to allow control of fonts, page styles, 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 or spell checkers must be created in order to accommodate mark-up languages. A special processor would recognize the mark-up language and strip it from the text so that the ``plain'' text could then be processed by a spell checker. For this problem, you are to write such a processor for a small mark-up language so that the output of your program will be the plain text without the mark-ups.

The mark-up language to consider is one which allows the modification of fonts within the text. Each markup command will be preceded by a \ character. If the letter following the \ character is not a recognized command from the table below then the character following the \ is printed as part of the plain text. For instance, the mark-up \\ can be used to print a single \.

tex2html_wrap_inline31 b
toggle bold font on/off (default state is off)
tex2html_wrap_inline31 i
toggle italics font on/off (default state is off)
tex2html_wrap_inline31 s
set font size; the s is immediately followed by an optional number; if the number is missing then the command will restore the previous size
tex2html_wrap_inline31 *
toggle processing of mark-ups on/off; if processing is toggled off then mark-ups are considered to be literal text (default state is on)

The number following the SPMamp& command can have a decimal point so 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 language above. 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.



這題題意沒有看很明確,一直掛 WA。

總歸結論,這題希望將讀入的 file.txt 當作一個 make-up,因此並不是每行獨立執行。

因此,會卡在 \* 指令跨行問題。

input:
\*
\s\b\\
\*

最後一行才將其功能關閉,只能說太賊了。

#include <stdio.h>
#include <string.h>
int main() {
char s[1005];
int i, j;
int tton = 0;
while(gets(s)) {
int len = strlen(s);
for(i = 0; i < len; i++) {
if(s[i] == '\\') {
if(s[i] == '\\' && s[i+1] != '*' && tton == 1)
goto L1;
if(s[i+1] == '\\') {
putchar('\\');
i++;
} else if(s[i+1] == 's') {
i++, i++;
while(s[i] >= '0' && s[i] <= '9')
i++;
if(s[i] == '.') {
i++;
while(s[i] >= '0' && s[i] <= '9')
i++;
}
i--;
} else if(s[i+1] == '*') {
i++;
if(tton) {
tton = 0;
continue;
}
tton = 1;
for(j = i+1; s[j]; j++) {
if(s[j] == '\\' && s[j+1] == '*') {
tton = 0;
break;
}
putchar(s[j]);
}
i = j+1;
} else if(s[i+1] == 'b' || s[i+1] == 'i')
{i++;}
} else {
L1:
putchar(s[i]);
}
}
puts("");
}
return 0;
}

台長: Morris
人氣(1,551) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][最短路] 12295 - Optimal Symmetric Paths
此分類上一篇:[UVA][time] 12136 - Schedule of a Married Man

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文