# | Problem | Pass Rate (passed user / total user) |
---|---|---|
12544 | Simple Web Crawer |
|
13383 | Cardcaptor Sakura2 |
|
13412 | I hate Christmas |
|
13798 | Haha...I love u |
|
13799 | The Christmas Ribbon |
|
13801 | Two Knights |
|
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
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
One day, you become a santa claus and have to send everyone gifts.
There is a line of people, and each one has a non-unique number card which represents what gifts they will receive.
(Because you are a smart santa claus, you use linked-list to record the numbers)
However, when you see there are so many couples standing together, you feel so angry and decide to rearrange the order with the following rule:
Given the head
of the linked list containing multiple groups (the size of each group is k
), reverse the nodes inside each group at a time.
k
is a positive integer and is less than or equal to the length of the linked list.
If the number of nodes is not a multiple of k,
then the left-out nodes in the end should remain the same order.
You are not allowed to alter the values in each node.
For example, when k = 2:
Note that it is a partial-judge problem that you need to implement the function:
Input
The first line is composed of a sequence of integer(1<= val <=100000000), which represents the values of the linked list.
The input stops when read in '-1' ('-1' is not a part of the 2 linked-lists).
The second line is k, the size of the group that will be reversed.(1 <= k <= length of the linked list)
Output
The values of the group-based reversed linked-list.
The values are separated by a whitespace and the output is also ended with a whitespace.
Sample Input Download
Sample Output Download
Partial Judge Code
13412.cPartial Judge Header
13412.hTags
Discuss
Description
This winter is very cold, JYL wants to find a female companion to accompany him through this cold winter.
In order to meet more girls, he decided to use dating software.
However, JYL is deeply afraid that his handsomeness will attract too many girls.
Therefore, he decided to find the girl who had the most in common with him to develop a relationship with.
The selection method is as follows:
Given two strings (representing the information of JYL and that girl), please calculate the length of the longest common subsequence of the two strings.
Hint: You can use a 2D table to record the intermediate results.
Note:
A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
For example, "ace" is a sequence of "abcde".
God bless him......
Input
There are two strings separated by a newline character.
Note that the length of the two strings are less than 3100.
Output
The length of the longest common sequence.
Note that you have to print '\n' in the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Camo needs a Christmas ribbon to celebrate this special day with her friends!
Given an integer array that contains N elements, and each element is an integer between 1 to K. We want to find the number of beautiful ribbons for Camo. A beautiful subarray has the following two properties:
1. The length of it is K.
2. Each number from 1 to K only appear once in the subarray.
Can you find out the number of beautiful ribbons in the given array? (notice that two beautiful ribbons can overlap)
For the testcase 1 ~ 6, 1 ≤ N, K ≤ 103
For the testcase 7 ~ 8, 1 ≤ N, K ≤ 106
Input
The first line contains two integers N and K
The next line contains N integers, which is the element of the array. (1 ≤ Ai ≤ K)
Output
Output the number of beautiful ribbons. Remember to print a newline character at the end of the line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
There are N knights in the city. In order to protect the city, you need to find two knights to protect the whole area.
There are K defending properties, two knights can protect the city perfectly if, for each property, at least one knight has it.
For example:
we'll use A1 = [1, 3] describing that the first knight has properties 1 and 3.
If K = 3, A1 = [1, 3], and A2 = [2, 3], they can protect the city perfectly.
However, if K = 5, A1 = [1, 3, 5] and A2 = [4, 5], they cannot protect the city since none of them has the defending property 2.
Given the properties of N knights, how many ways you can select two knights such that the city can be protected perfectly?
Testcase 1 ~ 6:
1 ≤ N ≤ 103, 1 ≤ K ≤ 10
Testcase 7 ~ 8:
N = 30000, K = 30
Hint: you can use bitwise operator to handle the testcase 7 and 8!
Input
There're two integers N and K, describing the number of knights and the number of properties.
For the next N lines, each line contains K digits (0 or 1). the k-th digit on the i-th line describes whether knight i has the property k.
Output
Output the number of ways you can choose to protect the city. Print a newline character at the end of the line.