UVa391 - Mark-up

本文介绍了一种小型标记语言的处理方式,该语言允许在文本中修改字体样式。文章详细解释了如何通过特殊处理器来识别并去除这些标记,以便进行拼写检查等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 \.

tex2html_wrap_inline31b
toggle bold font on/off (default state is off)
tex2html_wrap_inline31i
toggle italics font on/off (default state is off)
tex2html_wrap_inline31s
set font size; the s is immediately followed byan optional number; if the number ismissing then the command will restore the previous size
tex2html_wrap_inline31*
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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值