来源:点击打开链接

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

题目要求是将一串字母转化成网址——形如格式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. java中的substring用法

    String str="我是中国人"; str = str.substring(0, 2) +"_"+str.substring(3, 4); 结果:str=& ...

  2. source insight 完全卸载和重装

    Source insight的卸载不干净,会影响之后的安装 切入正题,完美卸载source insight的方法: 一.在pc的控制面板—>程序—>卸载程序 找到source insigh ...

  3. C# Winform常见的Editor及其它经验

    1.新建一个自定义Editor,继承自.NET自带的Editor,override某些方法,再附加到属性中: public class MyCollectionEditor : CollectionE ...

  4. RabbitMQ 3.6 安装

    1. 首先安装这个 http://www.erlang.org/downloads 2. 再安装这个 http://www.rabbitmq.com/install-windows.html 3. 添 ...

  5. 输出string vector到file

    #include <fstream> #include <iterator> #include <string> #include <vector> i ...

  6. 使用开关、分段控件和web视图

    #import "XViewController.h" @interface XViewController () @end @implementation XViewContro ...

  7. Asp.net 自定义控件开发相关的几种嵌入资源解决方案

    前提: 如下将要介绍的几种类型资源都要在其属性页窗口, 将 <生成操作> 属性, 设置为[嵌入的资源], 如图:   ► 给自定义控件添加自定义图标的几种方案   方法一: 直接在自定义控 ...

  8. ASP.NET MVC与RAILS3的比较

    进入后Web年代之后,MVC框架进入了快速演化的时代,Struts等垂垂老矣的老一代MVC框架因为开发效率低下而逐渐被抛弃,新一代的MVC则高举敏捷的大旗,逐渐占领市场,其中的代表有Rails (ru ...

  9. git的安装使用和代码自动部署

    1.安装 http://www.cnblogs.com/sunada2005/archive/2013/06/06/3121098.html http://www.cnblogs.com/zhcncn ...

  10. POJ 1459

    #include<iostream> #define MAXN 105 #include"queue" #define big_num 100000000 using ...