NOJ [1093] processing strings in HTML, that is, HDU1088

Source: Internet
Author: User

[2, 1093] HTML
Time Limit: 1000 MS memory limit: 65535 K
Problem description
If you ever tried to read a html document on a Macintosh, you know how hard it is if no Netscape is installed.
Now, who can forget to install a HTML browser? This is very easy because most of the times you don't need one on a MAC because there is a bytes bate Reader which is native to MAC. but if you ever need one, what do you do?
Your task is to write a small html-browser. it shoshould only display the content of the input-file and knows only the html commands (tags) <br> which is a linebreak and Input
The input consists of a text you shoshould display. This text consists of words and HTML tags separated by one or more spaces, tabulators or newlines.
A word is a sequence of letters, numbers and punctuation. for example, "abc, 123" is one word, but "abc, 123" are two words, namely "abc," and "123 ". A word is always shorter than 81 characters and does not contain any '<' or '> '. all HTML tags are either <br> or Output
You shoshould display the resulting text using this rules:
If you read a word in the input and the resulting line does not get longer than 80 chars, print it, else print it on a new line.
If you read a <br> in the input, start a new line.
If you read a The last line is ended by a newline character.
Sample Input
Hallo, dies ist eine
Ziemlich lange Zeile, die in Html
Aber nicht umgebrochen wird.
<Br>
Zwei <br> produzieren zwei Newlines.
Es gibt auch noch das tag Zwei Achtung mehrere Leerzeichen irritieren

Html genauso wenig wie


Mehrere Leerzeilen. sample output
Hallo, dies ist eine ziemlich lange Zeile, die in Html aber nicht umgebrochen
Wird.
Zwei

Produzieren zwei Newlines. Es gibt auch noch das tag
--------------------------------------------------------------------------------
Was einen Trenner darstellt. Zwei
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Produzieren zwei Horizontal Rulers. Achtung mehrere Leerzeichen irritieren Html
Genauso wenig wie mehrere Leerzeilen.
Prompt
No source
Ulm Local 1999
 
Enter 1 heap of characters. A maximum of 80 characters in each line. Each word is continuous. It is neither a word nor a separate character, such as a space tab. A word does not contain <> other symbols.
 
If <br> is encountered, a space is output.
If you encounter At the time of output, each line has a maximum of 80 characters, and each word has one space.
 
 
[Cpp]
# Include <stdio. h>
# Include <string. h>
Int main ()
{
Char str [100];
 
Int cnt = 0; // number of characters in each line
Bool first = true; // whether the record is the beginning of a row
While (scanf ("% s", & str )! = EOF)
{
If (strcmp (str, "<br>") = 0) {printf ("\ n"); cnt = 0; first = true; continue ;}
If (strcmp (str, "{
If (! First) {printf ("\ n"); first = true ;}
For (int I = 0; I <80; I ++) printf ("-");
Printf ("\ n"); first = true; cnt = 0;
Continue;
}
If (first)
{
Printf ("% s", str );
Cnt + = strlen (str); first = false;
Continue;
}
Cnt + = (strlen (str) + 1); first = false;
If (cnt <= 80)
{
Printf ("% s", str );
Continue;
}
Else
{
Printf ("\ n ");
Printf ("% s", str );
Cnt = strlen (str); first = false;
}
}
If (! First) printf ("\ n"); // end with a new line
Return 0;
}

# Include <stdio. h>
# Include <string. h>
Int main ()
{
Char str [100];

Int cnt = 0; // number of characters in each line
Bool first = true; // whether the record is the beginning of a row
While (scanf ("% s", & str )! = EOF)
{
If (strcmp (str, "<br>") = 0) {printf ("\ n"); cnt = 0; first = true; continue ;}
If (strcmp (str, "{
If (! First) {printf ("\ n"); first = true ;}
For (int I = 0; I <80; I ++) printf ("-");
Printf ("\ n"); first = true; cnt = 0;
Continue;
}
If (first)
{
Printf ("% s", str );
Cnt + = strlen (str); first = false;
Continue;
}
Cnt + = (strlen (str) + 1); first = false;
If (cnt <= 80)
{
Printf ("% s", str );
Continue;
}
Else
{
Printf ("\ n ");
Printf ("% s", str );
Cnt = strlen (str); first = false;
}
}
If (! First) printf ("\ n"); // end with a new line
Return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.