B. Internet Address codeforces-problem-245B
来源:互联网 发布:qq飞车飞虎雷诺数据 编辑:程序博客网 时间:2024/05/16 17:53
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".
理解题意后进行简单的判断,将原字符串分段定位,分批输出即可。
B:#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;int find_useful_r(char *str);int main(){//此代码一直将第一个ru作为.ru输出 char str[51]; scanf("%s",str); //printf("%d\n",sizeof(str)); if(str[0]=='h') { printf("http://"); int locator=find_useful_r(str); for(int i=4;i<locator;i++) printf("%c",str[i]); printf(".ru"); if(strlen(str)>locator+2)//如果".ru"后还有字符 { printf("/"); for(int i=locator+2;i<strlen(str);i++) printf("%c",str[i]); } } else//与http仅在第一次循环的初始条件有差异,其余复制 { printf("ftp://"); int locator=find_useful_r(str); for(int i=3;i<locator;i++) printf("%c",str[i]); printf(".ru"); if(strlen(str)>locator+2) { printf("/"); for(int i=locator+2;i<strlen(str);i++) printf("%c",str[i]); } }}int find_useful_r(char *str)//返回第一个可用的'r'的下标{ if(str[0]=='h') { for(int i=5;i<strlen(str);i++) if(str[i]=='r'&&str[i+1]=='u') return i; } else//"ru"前为domain,至少一个字符长度,故跳过协议名后的第一个字符 { for(int i=4;i<strlen(str);i++) if(str[i]=='r'&&str[i+1]=='u') return i; }}/*注意点:sizeof()返回的是字符串数组的大小而不是实际长度,此题应用strlen()*/
- B. Internet Address codeforces-problem-245B
- 【周全考虑】CodeForces 245B——Internet Address
- CodeForce-245B-Internet Address
- B. Internet Address
- Problem - 216B - Codeforces
- Problem - 218B - Codeforces
- codeforces problem/408/B
- Codeforces Problem - 50B
- Problem - 376B - Codeforces
- problem - 616B -codeforces
- Codeforces Problem 333B
- Codeforces Problem 332B
- B. Secret Combination codeforces-problem-496B
- B. Reading codeforces-problem-234B
- Codeforces Gym 100623B Problem B. Billboard
- codeforces-Problem 193B - Xor
- Codeforces Problem 499B. Lecture
- codeforces 278B New Problem
- 《Spark商业案例与性能调优实战100课》第6课:商业案例之通过Spark SQL实现大数据电影用户行为分析
- Mongoose的官方quick start教程
- MongoDB学习笔记(四)MongoDB查询集合中的文档
- 同一个ip下一个端口是否可以开两个服务器
- 数据结构的学习之路(二)-- 栈与队列
- B. Internet Address codeforces-problem-245B
- ImageLoader源码详解
- 设计一个可扩展的用户登录系统 (3)
- XML、DTD和Schema
- centos7 docker
- 微信小程序开发
- osgViewer::ViewerBase
- 软件工程UML图的学习(各种关系及线箭头疑点解析)
- gcm - linux下面的终端管理器 - 终于找到你了