来源:点击打开链接

看上去很简单的一道题,可是错的次数却不少。

题目要求是将一串字母转化成网址——形如格式http(ftp)://xxx.ru/xxxx的样子,看上去很简单,可是还是很容易出错。

刚开始找的时候是按照寻找第一组http/ftp,然后寻找第一个ru,构成网址,但是报错了,反例如下:httpruc

所以不能寻找第一个网址,也就是说尽量避免.ru之前没有东西,这样是不合法 的。然后注意http是四个字符,ftp只有三个字符,所以不能固定。。

#include <iostream>
#include <string>
using namespace std; int main()
{
string tar,res;
string tarstack;
int propos=0,ctpos=0;
cin>>tar;
if(tar[0]=='h')
{
tarstack="http";
}
if(tar[0]=='f')
{
tarstack="ftp";
}
ctpos=tar.find("ru",tarstack.length()+1); //5是不行的,惯性思维不可
if(tar[0]=='h')
{
cout<<tarstack<<"://";
for(int i=4;i<ctpos;i++)
{
cout<<tar[i];
}
cout<<".ru";
if(ctpos+2==tar.length())
cout<<endl;
else
{
cout<<"/";
for(int i=ctpos+2;i<tar.length();i++)
{
cout<<tar[i];
}
cout<<endl;
} }
else if(tar[0]=='f')
{
cout<<tarstack<<"://";
for(int i=3;i<ctpos;i++)
{
cout<<tar[i];
}
cout<<".ru";
if(ctpos+2==tar.length())
cout<<endl;
else
{
cout<<"/";
for(int i=ctpos+2;i<tar.length();i++)
{
cout<<tar[i];
}
cout<<endl;
}
}
return 0; }
//范例:httpruhhphhhpuhruruhhpruhhphruhhru

【周全考虑】CodeForces 245B——Internet Address的更多相关文章

  1. FileZilla上傳報錯:421 There are too many connections from your internet address

    起因:2019年01月27日晚九點左右,想要將一個50MB+的文件夾上傳到阿里雲的虛擬主機上,使用FTP 工具FileZilla,出現了上傳一段時間後提示421 There are too many ...

  2. How do I use a host name to look up an IP address?

    The InetAddress class can be used to perform Domain Name Server (DNS) lookups. For example, you can ...

  3. [转]Peer-to-Peer Communication Across Network Address Translators

    Peer-to-Peer Communication Across Network Address Translators Bryan Ford Massachusetts Institute of ...

  4. lwip IP address handling 关于 IP 地址的 操作 API接口

    lwip 2.0.3  IP address handling /** * @file * IP address API (common IPv4 and IPv6) */ 1.u32_t ipadd ...

  5. 网络编程-Java中的Internet查询

    前提 在深入理解URL.URI等概念,或者学些Socket相关的知识之,有必要系统理解一下Internet相关的一些基础知识. Internet地址 连接到Internet(因特网)的设备称为节点(n ...

  6. Converts Internet addresses to Internet numbers. ip2long long2ip

    http://php.net/manual/en/function.long2ip.phpPHP: ip2long - Manual http://php.net/manual/en/function ...

  7. TNS-12541: TNS:no listener , TNS-12542: TNS:address already in use

    查看数据库监听状态不对$ lsnrctl status LSNRCTL for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - Production on ...

  8. Linux Socket 网络编程

    Linux下的网络编程指的是socket套接字编程,入门比较简单.在学校里学过一些皮毛,平时就是自学玩,没有见识过真正的socket编程大程序,比较遗憾.总感觉每次看的时候都有收获,但是每次看完了之后 ...

  9. [协议]ICMP协议剖析

    1.ICMP简介 ICMP全名为(INTERNET CONTROL MESSAGE PROTOCOL)网络控制消息协议. ICMP的协议号为1. ICMP报文就像是IP报文的小弟,总顶着IP报文的名头 ...

随机推荐

  1. Servlet主要的作用

    1,收集Request传递过来的参数: 2,把这些参数组织成模型需要的类型: 3,调用模型进行逻辑功能处理: 4,选择下一个页面,先准备好一个页面需要的数据,然后转向下一个页面.

  2. ZOJ 3941 Kpop Music Party 贪心

    题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3941 题解: 先吧所给的区间合并,得到若干个独立的区间. 然后从左 ...

  3. File "/struts-tags" not found

    前言 由于在某个jsp引用了struts标签库,导致该错误产生--这是stuts项目算是一道经典错误,往往最后的解决方式是更换Tomcat.今天我记录的是引起这一错误的一个非常隐藏的原因. 错误描述 ...

  4. 【CentOS】安装chrome

    参考资料:http://www.cnblogs.com/xia520pi/p/3545715.html 问题描述: 出现如下错误: 升级glibc任然无效,最后在博客园:http://www.cnbl ...

  5. hdu 4004 The Frog's Games

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...

  6. 【POJ】【1821】Fence

    DP/单调队列优化 题意:k个人粉刷总长为n的墙壁(或者说栅栏?),每个人有一个必刷点s[i](这个人也可以一点也不刷,如果刷就必须刷这个点),最大粉刷长度l[i](必须是连续粉刷一段),和粉刷一格的 ...

  7. java 验证身份证号

  8. 在当前iframe中, 获取Iframe的id

    window.frameElement   返回嵌入当前window对象的元素(比如 <iframe> 或者 <object>),如果当前window对象已经是顶层窗口,则返回 ...

  9. mysql SQLyog导入导出csv文件

    1.选择数据库表 --> 右击属性 --> 备份/导出 --> 导出表数据作为 --> 选择cvs --> 选择下面的“更改” --> 字段 --> 变量长度 ...

  10. Linux 双线策略路由的三种实现方式总结+端口映射

    Linux 双线策略路由的三种实现方式总结+端口映射 Linux 双线策略路由的三种实现方式总结+端口映射 网络环境 服务器(网关): eth0 为LAN口,IP为 LAN_IP = 192.168. ...