# | Problem | Pass Rate (passed user / total user) |
---|---|---|
12544 | Simple Web Crawer |
|
13364 | Mom, don't do that |
|
13383 | Cardcaptor Sakura2 |
|
13391 | Domo the Train Conductor |
|
14180 | Domo the Super Train Conductor |
|
14182 | Dad, don't do that |
|
Description
A Web crawler, sometimes called a spider or spiderbot and often shortened to crawler, is an Internet bot that systematically browses the World Wide Web.
Generally, a Web crawler visits a website, reads the HTML code of the website, gathers information it wants, and probably wants to visit the links it found in this website.
For example, if a Web Crawler visits the wikipedia webpage introducing "Web crawer" (the webpage is shown in the left part of the image) ...
-
It reads the html code of the webpage (shown in the right part of the image)
-
It gathers information. For example,
-
It finds the definition of "Web Crawler"
-
It finds several links (i.e. the blue words in the webpage), such as links to "Internet bot", "World Wide Web", etc.
-
-
It probably wants to visit the links "Internet bot", "World Wide Web", ... one by one to get more information.
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?
-
Some useful functions you've learned in previous homework 12507 - Searching Remark :
-
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
"Mom, don't do that."
You have some secret folders which store a lot of videos about algorithm.
However, you do not want your mom know that you are interested in CS (she wants you to become a doctor).
Thus, you use a special trick to rearrange the original directory and sub-directory so it's difficult to directly access the folder.
Also, you make some fake directories, trying to make your mom more confused.
Although you think it's safe enough, your mom wrote a super program to check whether the decoded directory is valid or not.
Orz.
In order to figure out how your mom does that, you are going to design a similar program.
Given testcases T, each with two strings, O (origin directory) and D (decoded directory), please print "valid" if you can rearrange D into a sub-directory of O; if it's not possible, print "not valid".
Next time, remember to lock your room before leaving home.
hint. You can use string.h to make the problem easier.
Input
The first line of the input is an intger T, denoting the number of testcases. 1<= T <= 100
Next 2*T lines contain information of T pairs of O and D.
O is a directory, composed of a sequence of folders separated by a "/", e.g. "/home/hii/it/is/a/folder".
D is a decoded directory, which may be a sub-directory of O or an invalid directory:
example 1: "/hii/home/it", which is valid because you rearrange it into "/home/hii/it".
example 2: "/hii/it/home/nooo", which is invalid because "nooo" is not a part of folders of O.
1 <= length of O or D <= 5000
1 <= number of folders in O <= 50
Note that O and D must start from a "/", and there is no "/" in the end and each folder may appear more than once.
Output
For each testcases, if D may be valid, print "valid".
Otherwise, print "not valid".
Note that you have to print "\n" after each answer.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The problem is modified from 13361 - Cardcaptor Sakura.
You have to implement two more instructions (1) shiftleft (2) shiftright in this problem.
There are 10 tables (indexed from 0 to 9) and no cards on them initially.
Given a command S, Sakura has to follow the instructions below:
(1) print: print the status of each table with the format :"table_idx: cards_on_the tables\n", e.g. "0: 1 3 3 4 5\n".
Note that if there are no cards, print "No card".
(2) all num len : Place len cards on each table, and the value on each card is num .
For example, the instruction "all 3 4" changes the status of each table to "table_idx: 3 3 3 3\n";
(3)
place table_idx len
integer_sequence
: Place a stack of cards on table table_idx. len means the number of cards in the stack. An integer sequence integer_sequence of length len is given, in which each integer means the value on the placed card.
For example, the instruction will be like:
place 2 3
3 2 1
And the status of Table_2 will become:
2: 3 2 1
Note that if there are cards 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: 1 2 3
1: 4 5 6
after "swap 0 1", the status of the two tables become:
0: 4 5 6
1: 1 2 3
This instruction is valid even if one of the tables is empty.
(5) clear: Clean all the tables.
(6) exit: terminates
(7) shiftleft: Move each pile of cards to its left. For table 0, move the cards to table 9.
For example:
If the origin status of tables are:
0: 1 1 1
1: 2 2 2
2: 3 3 3
3: 4 4 4
4: 5 5 5
5: 6 6 6
6: 7 7 7
7: 8 8 8
8: 9 9 9
9: 10 10 10
afeter shiftleft, it'll become:
0: 2 2 2
1: 3 3 3
2: 4 4 4
3: 5 5 5
4: 6 6 6
5: 7 7 7
6: 8 8 8
7: 9 9 9
8: 10 10 10
9: 1 1 1
(8) shiftright: Move each pile of cards to its right. For table 9, move the cards to table 0.
For example:
If the origin status of tables are:
0: 1 1 1
1: 2 2 2
2: 3 3 3
3: 4 4 4
4: 5 5 5
5: 6 6 6
6: 7 7 7
7: 8 8 8
8: 9 9 9
9: 10 10 10
afeter shiftright, it'll become:
0: 10 10 10
1: 1 1 1
2: 2 2 2
3: 3 3 3
4: 4 4 4
5: 5 5 5
6: 6 6 6
7: 7 7 7
8: 8 8 8
9: 9 9 9
Input
Commands separated by a newline character.
Note that:
1 <= the value of each card <= 13
1 <= number of cards on each table <= 10000
Note that only testcase 1, 5, and 6 contains shiftleft and shiftright.
Output
Status of each table.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Domo is a train conductor, he wants to adjust the train he's driving.
There are five instructions below with the description:
1. AddFront num
Add a train carriage with the index num in front of the train.
2. AddBack num
Add a train carriage with the index num in back of the train.
3. Delete num
Delete all the train carriages with the index num from the train. (If the train has no any carriage with the index num, do nothing)
4. DeleteFront
Delete the first element of the train. (If the train is empty, do nothing)
5. Swap
Reverse all train carriages. (If the train is empty, do nothing)
For example:
AddFront 5 makes the train [4, 1] become [5, 4, 1].
AddBack 5 makes the train [4, 1] become [4, 1, 5].
Delete 5 makes the train [5, 4, 1, 5, 3] become [4, 1, 3].
DeleteFront make the train [1, 2, 3, 4] become [2, 3, 4].
Swap makes the train [2, 6, 3] become [3, 6, 2].
The train is empty in the beginning. Given a series of instructions, please print the index of train carriages after all instructions are executed.
This is a partial judge problem, you're asked to implement these 5 functions.
If you get a TLE:
Try to use the pointer head and back wisely, which can make the AddFront and AddBack instructions faster!
If you get an MLE:
Remember to free the nodes you've deleted!
Input
The input consists of multiple instructions (1 ≤ number of instructions ≤ 105)
the index of each instruction is a positive integer and not greater than 102.
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
13391.cPartial Judge Header
13391.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.
Sample Input Download
Sample Output Download
Partial Judge Code
14180.cPartial Judge Header
14180.hTags
Discuss
Description
"Dad, don't do that"
Your dad cares about your friendship status. So, he decided to log into your social media to see who you were chatting with. Due to security issues, your password has been encrypted by adding extra K digits. Unfortunately, the original password is the smallest solution after removing K digits from the encrypted password.(e.g., for 1432219, if k = 3, the solution will be 1219)
Thus, it is easy for him to get the original password.
Although you felt sad, you were still curious about how he did it. So, you decide to write a program to do the same thing as your dad.
Note that, if there is a leading 0 after removing K digits, it is still legal, but you don't have to print the leading 0s.
For example, for 10200, if k = 1, the minimum result is 0200, where you should print "200".
Hint: You can use the concept of "stack", and push or pop each digit according to the top element of the stack.
Input
The first line is a sequence of digits, the length will be less than 1000001.
The second line is an integer K, which is the number of digits that will be removed. K will be less than 500001.
Output
The minimum integer after removing K digits and you should print a new line character in the end.