# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14197 | CS website part 1 |
|
14198 | CS website part 2 |
|
14199 | CS website part 3 |
|
14200 | Domo the Super Train Destroyer |
|
14201 | Domo the Super Train Conductor |
|
Description
This problem is based on "Simple Web Crawler".
In this problem, you are going to implement a simple Web crawler. Given the html code of some website, you are going to output several information :
-
Title of the website
The title of the website is the string placed within <title>
and </title>
, for example, the title in sample input is "This is the title".
-
Numbers of links in this webpage
A link in html is in the following syntax : <a href="url">link text</a>
, where url
is the link address and link text
is the text of the link.
Refer to the to Sample IO for output format.
Hints
-
What is html code?
-
In this problem, you only need to know that html code are several lines of strings in some special format.
-
html code are tags in the following format :
<tagname>contents of tag</tagname>
-
In Chrome, you can press
F12
key to see the html code of the website
-
-
How to read in html codes?
-
char *strtok(char *str, const char *delim)
- to break stringstr
into a series of tokens using the delimiterdelim
, which is defined understring.h
-
char *fgets(char *str, int n, FILE *stream)
- to read a string of lengthn
into stringstr
from a file streamstream
(e.g.stdin
), which is defined understdio.h
-
-
How to find title?
-
Why not start with finding the position of
<title>
and</title>
? The substring between<title>
and</title>
is the title of the website.
-
-
How to count links?
-
For every link in html, it must contains the substring
</a>
. This problem can be solved by counting the number of occurrence of</a>
.
-
Input
You will be given a HTML code. Input contains at most 100 lines. Each line contains at most 1000 characters.
Technical Restrictions
Only the following tags will appear in the input :
-
<html> </html>
-
<head> </head>
-
<body> </body>
-
<title> </title>
-
<a> </a>
-
<h1> </h1>
-
<p> </p>
All tags except for <head></head>
and <body></body>
will be on the same line.
In each case, there will be exactly one <head></head>
, one <body></body>
, one <title></title>
.
It is guaranteed that the contents of tags will not contain '<' or '>'.
Output
For the first line, please output the title of the given website.
For the second line, please output the number of links in the given website.
Remember to add new line character in the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The problem is modified from "Cardcaptor Sakura2".
In "Cardcaptor Sakura2", all the values are integers, but in this problem, you need to store chars on each table.
There are 10 tables (indexed from 0 to 9) and no contents on them initially.
Given a command S, you have to follow the instructions below:
(1) print: print the status of each table with the format :"table_idx: contents_on_the tables\n", e.g. "0: abc\n".
Note that if there are no contents, print "No Contents".
(2) all c len : Place len chars on each table, and the value is c .
For example, the instruction "all m 4" changes the status of each table to "table_idx: mmmm\n";
(3)
place table_idx
STRING
: Place a string STRING on table table_idx.
For example, the instruction will be like:
place 2
Hello
And the status of Table_2 will become:
2: Hello
Note that if there are contents already on the target table, the status will be overridden.
(4) swap table_a table_b: Swap the cards on table_a and table_b.
For example:
If the origin status of table 0 and table 1 are:
0: abc
1: def
after "swap 0 1", the status of the two tables becomes:
0: def
1: abc
This instruction is valid even if one of the tables is empty.
(5) clear: Clean all the tables.
(6) exit: terminates
(7) shiftleft: Move the contents on each table to its left. For table 0, move the contents to table 9.
For example:
If the origin status of tables is:
0: aaa
1: bbb
2: ccc
3: ddd
4: eee
5: fff
6: ggg
7: hhh
8: iii
9: jjj
after the shift, it'll become:
0: bbb
1: ccc
2: ddd
3: eee
4: fff
5: ggg
6: hhh
7: iii
8: jjj
9: aaa
(8) shiftright: Move each pile of cards to its right. For table 9, move the contents to table 0.
For example:
If the origin status of tables are:
0: aaa
1: bbb
2: ccc
3: ddd
4: eee
5: fff
6: ggg
7: hhh
8: iii
9: jjj
after shiftright, it'll become:
0: jjj
1: aaa
2: bbb
3: ccc
4: ddd
5: eee
6: fff
7: ggg
8: hhh
9: iii
Input
Commands separated by a newline character.
Note that:
The maximum length of each content should be less than 10001.
Each content is only composed of digits and letters (e.g., 1 or "A").
Output
Status of each table and you have to print a newline characters at the end of each line.
Note that you don't have to print space between chars on each table.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
In this problem, you have to implement a website editor by combining 13573 - CS website part 1 and 13574 - CS website part 2.
First, you have to read a html code.
It is guaranteed that the format of the html code must satisfy:
<html> <head> <title>{THE CONTENT OF THE TITLE}</title> </head> <body> <{TAG}>{THE CONTENT OF THE BODY}</{TAG}> ...... <{TAG}>{THE CONTENT OF THE BODY}</{TAG}> </body> </html>
(The number of spaces are 3 and 6 separately)
TAG may be h1 or p here and it is guaranteed that there are no nested structures (only one tag type in each line).
For example:
<html> <head> <title>Good Luck!</title> </head> <body> <h1>Have Fun! 0</h1> <p>Have Fun! 1</p> <h1>Have Fun! 2</h1> <p>Have Fun! 3</p> </body> </html>
After you read the html code, you'll get an initial title and arbitrary amounts of content.
In the following steps, you can treat the contents of the h1 and p tags as the two groups of tables in 13574 - CS website part 2.
The order of the contents is calculated separately.
For example, the content of the 0th table in h1 tags is "Have Fun! 0"; the content of the 1st table in h1 tags is "Have Fun! 2".
The content of the 0th table in p tags is "Have Fun! 1"; the content of the 1st table in p tags is "Have Fun! 3".
Based on the rule in 13574 - CS website part 2, given a command S, you have to follow the instructions below:
The difference between this problem and 13574 - CS website part 2 is that you have to choose which group of tables is going to be operated according to TAG(H1 or P).
(1) print: print the current html code using the predefined format. Since we'll only modify the contents in the tag, the order of the different types of tags in the body should be the same(e.g., h1->p->h1->p in the previous example).
Note that if the content is cleared, the content will be represented in "No Contents".
(2) all{TAG} c len : Place len chars on each table in TAG, and the value is c .
For example, the instruction "allH1 m 4" changes the contents of each table in h1 to "mmmm";
(3)
place{TAG} table_idx
STRING
: Place a string STRING on table table_idx.
For example, the instruction will be like:
placeP 2
Hello
And the content of Table_2 in p will become "Hello".
Note that the original contents will be overridden.
(4) swap{TAG} table_a table_b: Swap the cards on table_a and table_b in TAG.
For example:
If the origin html code is:
<html> <head> <title>Good Luck!</title> </head> <body> <h1>Have Fun! 0</h1> <p>Have Fun! 1</p> <h1>Have Fun! 2</h1> <p>Have Fun! 3</p> </body> </html>
after "swapH1 0 1", the html code becomes:
<html> <head> <title>Good Luck!</title> </head> <body> <h1>Have Fun! 2</h1> <p>Have Fun! 1</p> <h1>Have Fun! 0</h1> <p>Have Fun! 3</p> </body> </html>
This instruction is valid even if one of the contents is empty.
(5) clear: Clean all the tables in both h1 and p.
(6) exit: terminates
(7) shiftleft{TAG}: Move the contents on each table in TAG to its left. For table 0, move the contents to the last table in TAG.
(8) shiftright{TAG}: Move the contents on each table in TAG to its right. For the last table, move the contents to the table 0 in TAG.
(9)
Newtitle
STRING
: Replace the title with a string STRING.
Input
The input is composed of two parts.
The first part is the initial html code.
The second part is the instruction sets.
Note that:
The maximum length of each content or title should be less than 10001.
The number of h1 and p is less than 100, respectively.
Output
The modified html code.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Domo is a super train destroyer, he wants to adjust the train he's driving.
There are two instructions below with the description:
1. AddBack N
The AddBack instructions will be followed by N numbers on the seccond line, representing train carriages that you need to add them at the back of the current train.
2. LinearDelete
Delete carriages using the linear delete rule.
Example of AddBack:
AddBack 5
1 3 2 4 5
makes the train [4, 1] become [4, 1, 1, 3, 2, 4, 5].
AddBack 3
3 1 2
makes a empty train [] become [3, 1, 2].
Linear delete rule:
1. Consider the first carriage as the "DEL" carriage, repeat steps 2~4 until you step out from the back of the train at step 4.
2. Store the index of the DEL carriage in the variable K.
3. Move forward K steps, and assign the carriage after K steps as the new DEL carriage. (If step out from the end of the train, terminate when you finish step 4)
4. Delete the old DEL carriage (the beginning carriage in step 3), and back to step 2 if we haven't stepped out from the end of the train, otherwise terminate.
For example:
suppose the current train is [3, 1, 3, 2, 4, 2, 6, 4, 2, 7, 3, 2] and the instruction is LinearDelete
1. At the beginning, the DEL carriage is '3'.
2. Since DEL carriage is '3', we step forward 3 steps. Hence, the new DEL carriage is '2'.
3. we delete the old DEL carriage.
4. Repeat the procedure until we step out of the train.
In this case, the last movement moves out from the carriage '2' to the outside of the train. Hence, after we delete the '2' carriage, we terminate the instruction.
5. The result will be [1, 3, 4, 6, 2, 7, 3].
The train is empty in the beginning. Given a series of instructions, please print the index of train carriages after all instructions are executed. The first instruction must be AddBack.
This is a partial judge problem, you're asked to implement these 2 functions.
Hint: Carefully maintain Node** head and back!
Input
The input consists of multiple instructions (1 ≤ number of instructions ≤ 103)
the index of AddBack will be positive integers, and:
Testcase 1: 2 ≤ index ≤ 100
Testcase 2: 1 ≤ index ≤ 100
the integer N in AddBack will not greater than 103.
Output
The output only consists of a line denoting the train carriage indices after all the instructions.
It's guaranteed that the output consists of at least one carriage.
Sample Input Download
Sample Output Download
Partial Judge Code
14200.cPartial Judge Header
14200.hTags
Discuss
Description
Domo is a super train conductor, he wants to adjust the train he's driving.
There are two instructions below with the description:
1. AddBack N
The AddBack instructions will be followed by N numbers on the seccond line, representing train carriages that you need to add them at the back of the current train.
2. CircularInsert N M
Add N carriages with index M using the circular insert rule.
Example of AddBack:
AddBack 5
1 3 2 4 5
makes the train [4, 1] become [4, 1, 1, 3, 2, 4, 5].
AddBack 3
3 1 2
makes a empty train [] become [3, 1, 2].
Circular insert rule:
1. Repeat steps 2~4 N times. Initially, consider the first carriage as the "NOW" carriage.
2. Insert a carriage with index M right after the NOW carriage.
3. Store the index of the NOW carriage in the variable K.
4. Move forward K steps, and assign the carriage after K steps as the new NOW carriage. (If reaching the end of the train, go to the beginning of the train.)
For example:
suppose the current train is [3, 4, 5, 6] and the instruction is CircularInsert 3 2
1. At the beginning, the NOW carriage is '3', and we insert a carriage '2' right after it.
2. Since NOW carriage is '3', we step forward 3 steps. Hence, the next NOW carriage is '5'.
3. we insert a carriage '2' right after '5'.
4. Since NOW carriage is '5', we step forward 5 steps. Hence, the next NOW carriage is '4'. Notice that we go to the beginning if we step out the last carriage.
5. Insert a carriage '2' right after '5'. The result will be [3, 2, 4, 2, 5, 2, 6].
Notice that if the NOW carriage is the last one, you need to insert it right after it, not at the beginning.
The train is empty in the beginning. Given a series of instructions, please print the index of train carriages after all instructions are executed. The first instruction must be AddBack.
This is a partial judge problem, you're asked to implement these 2 functions.
Input
The input consists of multiple instructions (1 ≤ number of instructions ≤ 103)
the index of each instruction is a positive integer and not greater than 102.
the integer N in both instruction will not greater than 103.
Output
The output only consists of a line denoting the train carriage indices after all the instructions.
It's guaranteed that the output consists of at least one carriage.