/*
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:

“://” [ ":" ] [ "/" ]

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,

is always one of http, ftp or gopher.

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

is a positive integer, smaller than 65536.

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 stringinstead. 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 = 
Path = acm

URL #3
Protocol = gopher
Host = veryold.edu
Port = 
Path = 
*/

#include <string>
#include <iostream> using namespace std; int main()
{
int n; string s; cin >> n;
for(int i = 1; i <= n; i++)
{
int p;
cin >> s; p = s.find("://"); string protocol = s.substr(0, p);
string host = s.substr(p + 3, s.size());
string port;
string path; p = host.find('/');
if(p != string::npos)
{
path = host.substr(p + 1, host.size());
host = host.substr(0, p);
} p = host.find(':');
if(p != string::npos)
{
int k;
for(k = p + 1; isdigit(host[k]); k++)
port += host[k];
host = host.substr(0, p);
} cout << "URL #" << i << endl
<< "Protocol = " << protocol << endl
<< "Host = " << host << endl
<< "Port = " << (port == "" ? "<default>" : port) << endl
<< "Path = " << (path == "" ? "<default>" : path) << endl << endl;
} return 0;
}

ZOJ 1243 URLs的更多相关文章

  1. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  2. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  3. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  4. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  5. Django基础,Day2 - 编写urls,views,models

    编写views views:作为MVC中的C,接收用户的输入,调用数据库Model层和业务逻辑Model层,处理后将处理结果渲染到V层中去. polls/views.py: from django.h ...

  6. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  7. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  8. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  9. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

随机推荐

  1. C语言中文件的读取和写入

    在C语言中写文件 //获取文件指针 FILE *pFile = fopen("1.txt", //打开文件的名称 "w"); // 文件打开方式 如果原来有内容 ...

  2. 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision

    char *ptr; //此后省略部分代码 ) //出错地方 那句话的意思是从 void* 到 int 的转换丢失精度,相信看到解释有些人就明白了, 此问题只会出现在X64位的Linux上,因为在64 ...

  3. 怎么用navicat自动备份mysql数据库

    打开navicat客户端,连上mysql后,双击左边你想要备份的数据库.点击“计划”,再点击“新建批处理作业”.   双击上面的可用任务,它就会到下面的列表里去,代表你选择了这个任务.   点击保存, ...

  4. java web 之 web.xml篇

    web.xml文件 标签: 1. <web-app> 顶层标签,所有web.xml必须包含该标签.在该标签中,描述了当前Servlet版本以及其他一些信息. 2. <servlet& ...

  5. 在ubunut下使用pycharm和eclipse进行python远程调试

    我比较喜欢Pycharm,因为这个是JetBrains公司出的python IDE工具,该公司下的java IDE工具--IDEA,无论从界面还是操作上都甩eclipse几条街,但项目组里有些人使用e ...

  6. 关于process

    http://docs.oracle.com/javase/1.5.0/docs/api/ The ProcessBuilder.start() and Runtime.exec methods cr ...

  7. Ubuntu 14.10 下CPU实时监控mpstat命令详解

    简介 mpstat是Multiprocessor Statistics的缩写,是实时系统监控工具.其报告与CPU的一些统计信息,这些信息存放在/proc/stat文件中.在多CPUs系统里,其不但能查 ...

  8. linux添加动态库搜索路径

    在有时运行程序出现动态库找不着的问题,而明明装了的.这时候可能是没有将相应的路径添加到系统中去. 具体说:cd /etc/ld.so.conf.d/ 可以发现里面有一堆*.conf的文件 我们要做的就 ...

  9. Java 嵌套作用域

    在C/C++中,当一个块处于另一个块作用域内的时候,内层定义的变量会把外层的变量隐藏, 遵循所谓的就近原则. 在Java中,在内层定义与外层同名的变量是禁止的! 如下: int i = 0; for( ...

  10. 怎么在官网下载jstl【配图详解】

    JSTL(JSP Standard Tag Library,JSP标准标签库)是一个非常优秀的开源JSP标签库,如果要在系统使用JSTL标签,则必须将jstl.jar和 standard.jar文件放 ...