• <FZU1033>URLs


    URLs
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    In the early nineties, the World Wide Web (WWW) was invented. Nowadays, most people think that the WWW simply consists of all the pretty (or not so pretty) HTML-pages that you can read with your WWW browser. But back then, one of the main intentions behind the design of the WWW was to unify several existing communication protocols.

    Then (and even now), information on the Internet was available via a multitude of channels: FTP, HTTP, E-Mail, News, Gopher, and many more. Thanks to the WWW, all these services can now be uniformly addressed via URLs (Uniform Resource Locators). The syntax of URLs is defined in the Internet standard RFC 1738. For our problem, we consider a simplified version of the syntax, which is as follows:

    <protocol> "://" <host> [ ":" <port> ] [ "/" <path> ]

    The square brackets [] mean that the enclosed string is optional and may or may not appear. Examples of URLs are the following:

    http://www.informatik.uni-ulm.de/acm
    ftp://acm.baylor.edu:1234/pub/staff/mr-p
    gopher://veryold.edu

    More specifically,

    <protocol> is always one of http, ftp or gopher.

    <host> is a string consisting of alphabetic (a-z, A-Z) or numeric (0-9) characters and points (.).

    <port> is a positive integer, smaller than 65536.

    <path> is a string that contains no spaces.

    You are to write a program that parses an URL into its components.


    Input

    The input starts with a line containing a single integer n, the number of URLs in the input. The following n lines contain one URL each, in the format described above. The URLs will consist of at most 60 characters each.


    Output

    For each URL in the input first print the number of the URL, as shown in the sample output. Then print four lines, stating the protocol, host, port and path specified by the URL. If the port and/or path are not given in the URL, print the string <default> instead. Adhere to the format shown in the sample output.

    Print a blank line after each test case.


    Sample Input

    3
    ftp://acm.baylor.edu:1234/pub/staff/mr-p
    http://www.informatik.uni-ulm.de/acm
    gopher://veryold.edu
    

    Sample Output

    URL #1
    Protocol = ftp
    Host     = acm.baylor.edu
    Port     = 1234
    Path     = pub/staff/mr-p
    
    URL #2
    Protocol = http
    Host     = www.informatik.uni-ulm.de
    Port     = <default>
    Path     = acm
    
    URL #3
    Protocol = gopher
    Host     = veryold.edu
    Port     = <default>
    Path     = <default>
    
    
    //Memory: 228 KB		Time: 0 MS
    //Language: GNU C++		Result: Accepted
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    int main()
    {
        char s[61];
        int n, i;
        scanf("%d", &n);
        for(int ca=1; n--; ca++)
        {
            i = 0;
            scanf("%s", s);//puts(s);
            printf("URL #%d\n", ca);
            if(s[i] == 'h')
            {
                puts("Protocol = http");
                i+=7;
            }
            else if(s[i] == 'f')
            {
                puts("Protocol = ftp");
                i+=6;
            }
            else
            {//cout<<s[i];
                puts("Protocol = gopher");
                i+=9;
            }
            printf("Host     = ");
            for(; s[i] != '\0' && s[i] != ':' && s[i] != '/'; i++)
            {
                putchar(s[i]);
            }
            puts("");
            if(s[i] != ':')
                puts("Port     = <default>");
            else
            {
                printf("Port     = ");
                for(i++; s[i] != '\0' && s[i] != '/'; i++)
                {
                    putchar(s[i]);
                }
                puts("");
            }
            if(s[i] != '/')
                puts("Path     = <default>");
            else
            {
                printf("Path     = ");
                for(i++; s[i] != '\0'; i++)
                {
                    putchar(s[i]);
                }
                puts("");
            }
            puts("");
        }
        return 0;
    }


  • 相关阅读:
    Linux下查看CPU型号,内存大小,硬盘空间的命令
    java_opts 参数与JVM内存调优
    less 查看日志
    如何实时查看Linux下日志
    mysql的sql语句的性能诊断分析
    使用zabbix-java-gateway可以通过该网关来监听多个JVM
    性能瓶颈分析
    Git客户端的安装与配置入门
    渗透测试的8个步骤 展现一次完整的渗透测试过程及思路
    Python&selenium&tesseract自动化测试随机码、验证码(Captcha)的OCR识别解决方案参考
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910582.html
Copyright © 2020-2023  润新知