首页 > ACM题库 > HDU-杭电 > HDU 4018-Parsing URL-字符串-[解题报告]HOJ
2015
04-15

HDU 4018-Parsing URL-字符串-[解题报告]HOJ

Parsing URL

问题描述 :

In computing, a Uniform Resource Locator or Universal Resource Locator (URL) is a character string that specifies where a known resource is available on the Internet and the mechanism for retrieving it.
The syntax of a typical URL is:
scheme://domain:port/path?query_string#fragment_id
In this problem, the scheme, domain is required by all URL and other components are optional. That is, for example, the following are all correct urls:
http://dict.bing.com.cn/#%E5%B0%8F%E6%95%B0%E7%82%B9
http://www.mariowiki.com/Mushroom
https://mail.google.com/mail/?shva=1#inbox
http://en.wikipedia.org/wiki/Bowser_(character)
ftp://fs.fudan.edu.cn/
telnet://bbs.fudan.edu.cn/
http://mail.bashu.cn:8080/BsOnline/
Your task is to find the domain for all given URLs.

输入:

There are multiple test cases in this problem. The first line of input contains a single integer denoting the number of test cases.
For each of test case, there is only one line contains a valid URL.

输出:

There are multiple test cases in this problem. The first line of input contains a single integer denoting the number of test cases.
For each of test case, there is only one line contains a valid URL.

样例输入:

3

http://dict.bing.com.cn/#%E5%B0%8F%E6%95%B0%E7%82%B9


http://www.mariowiki.com/Mushroom


https://mail.google.com/mail/?shva=1#inbox

样例输出:

Case #1: dict.bing.com.cn
Case #2: www.mariowiki.com
Case #3: mail.google.com

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4018

The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup

题目大意:在一个长串中截取指定字符间的字符串,此处为截取//和/或:之间的字符串。

直接利用c函数sscanf解决。

代码:

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>

using namespace std;

int main()
{
    char str[2000];
    char buf[2000];
    int t;
    scanf("%d",&t);
    for (int i=1;i<=t;i++)
    {
        printf("Case #%d: ",i);
        cin>>str;
        sscanf(str,"%*[^/]//%[^/:]",buf);//截取
        cout<<buf<<endl;
    }
    return 0;
}

The 36th ACM/ICPC
Asia Regional Shanghai Site —— Warmup


hdu 4018 Parsing URL 

hdu 4018 Parsing URL 

hdu 4018 Parsing URL 


hdu 4018 Parsing URL 

hdu 4018 Parsing URL 

hdu 4018 Parsing URL 

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/iaccepted/article/details/6763706


  1. Thanks for taking the time to examine this, I really feel strongly about it and love studying a lot more on this topic. If possible, as you acquire experience