1872 - I2P(I)2019_Yang_CS_lab12 Scoreboard

Time

2019/12/17 18:30:00 2019/12/17 20:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11275 Sentence Reversal
12544 Simple Web Crawer

11275 - Sentence Reversal   

Description

In this problem, you are given several sentences, and you have to print the reversal of each of them.

A reversal of a sentence is the reversed order of words in the original sentence. For example, for the input string "this is a book", the result should be "book a is this".

Hint 1: we suggest you to do the task by a recursive function. The function seeks the first word from current location, and call itself recursively. Before each return, the function will print the word it found. Then all words will be printed in the reversed order.

The function prototype is something like this:

    void sentence_reversal( char *now ) ;    // which seek the first word from *now, and pass an new *now location to the called function

And the recursion is like the following figure:

this       (4th printed word)
    -> is      (3rd printed word)
        -> a       (2nd printed word)
            -> book  (1st printed word)

Hint 2: Print the spaces between words, and there should be no blanks (spaces) at the begin or the end of new sentences. If the original sentence has only one word, print the word directly without any spaces.

Note: Another method to solve this problem is seeking words from the end of the original sentence. But we strongly recommend you to try the recursive way as a practice.

Hint 3: Use fgets(). (https://www.dummies.com/programming/c/how-to-use-the-fgets-function-for-text-input-in-c-programming/)

Input

There are several lines of input, and each line presents a sentence.

No lines are longer than 500 characters, and there will be no empty lines. At most 10 sentences will appear in a test case.

Words in sentences are separated by a space (' '). There will be no continuous spaces, or any spaces at the beginning or end of the sentences.

Output

Print out each reversal sentence. All words in a reversal sentence are separated by a space, and there is a '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




12544 - Simple Web Crawer   

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

  1. It reads the html code of the webpage (shown in the right part of the image)

  2. It gathers information. For example,

    1. It finds the definition of "Web Crawler"

    2. It finds several links (i.e. the blue words in the webpage), such as links to "Internet bot", "World Wide Web", etc.

  3. 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 string str into a series of tokens using the delimiter delim, which is defined under string.h

    • char *fgets(char *str, int n, FILE *stream) - to read a string of length n into string str from a file stream stream (e.g. stdin), which is defined under stdio.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