B. Internet Address
来源:互联网 发布:算法导论 英文版 pdf 编辑:程序博客网 时间:2024/06/12 09:55
Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:
where:
- <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes),
- <domain> is a non-empty string, consisting of lowercase English letters,
- the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters.
If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context).
When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".".
Help Vasya to restore the possible address of the recorded Internet resource.
The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only.
It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above.
Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them.
httpsunrux
http://sun.ru/x
ftphttprururu
ftp://http.ru/ruru
In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru".
解题说明:此题就是把一个去掉分隔符的网络地址还原,这里只有http和ftp两种协议,可以先判断首字母,然后再定位ru的位置。注意如果协议名后直接跟着ru这时不应该把ru看成是域名后缀,因为http://.ru/xxxx是一个非法的url,所以要跳过一位查找。
#include<iostream>#include<map>#include<string>#include<algorithm>#include<cstdio>#include<cmath>using namespace std;int main(){char a[52];int j,i;scanf("%s",&a);if(a[0]=='h'){printf("http://");printf("%c",a[4]);for(i=5;a[i]!='\0';i++){if(a[i]=='r'&&a[i+1]=='u'){break;}printf("%c",a[i]);}printf(".ru");if(a[i+2]!='\0'){printf("/");for(j=i+2;a[j]!='\0';j++){printf("%c",a[j]);}}printf("\n");}else{printf("ftp://");printf("%c",a[3]);for(i=4;a[i]!='\0';i++){if(a[i]=='r'&&a[i+1]=='u'){break;}printf("%c",a[i]);}printf(".ru");if(a[i+2]!='\0'){printf("/");for(j=i+2;a[j]!='\0';j++){printf("%c",a[j]);}}printf("\n");}return 0;}
- B. Internet Address
- CodeForce-245B-Internet Address
- B. Internet Address codeforces-problem-245B
- 【周全考虑】CodeForces 245B——Internet Address
- CF245B Internet Address
- The Internet (IPv4) socket address structure: sockaddr_in.
- c4 Internet Address - Inet4Address and Inet6Address
- c4 Internet Address - The NetworkInterface class
- c4 Internet Address - Some useful Program
- Internet Protocol Address and Network Mask
- address
- Address
- address
- address
- address
- address
- Address
- address
- 优酷获得.m3u8的方法
- Win7 上网本无法搜索wifi热点
- Java对Map进行按值排序 (转)
- iOS-系统声音列表及调用
- 前员工爆料百度百伯夭折内幕:烧钱3亿只会挖人复制
- B. Internet Address
- Windows7系统U盘加密方法
- linux jdk安装步骤
- 玩转Win7媒体中心 轻松看网络电视
- Oracle删除Archivelog
- assert()函数用法总结
- 槽神也说自动化测试有效性
- 关于输入框的限制问题(百度百科转载)
- 一个简单的 弹性返回顶部JS代码