【周全考虑】CodeForces 245B——Internet Address
来源:点击打开链接
看上去很简单的一道题,可是错的次数却不少。
题目要求是将一串字母转化成网址——形如格式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的更多相关文章
- FileZilla上傳報錯:421 There are too many connections from your internet address
起因:2019年01月27日晚九點左右,想要將一個50MB+的文件夾上傳到阿里雲的虛擬主機上,使用FTP 工具FileZilla,出現了上傳一段時間後提示421 There are too many ...
- 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 ...
- [转]Peer-to-Peer Communication Across Network Address Translators
Peer-to-Peer Communication Across Network Address Translators Bryan Ford Massachusetts Institute of ...
- 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 ...
- 网络编程-Java中的Internet查询
前提 在深入理解URL.URI等概念,或者学些Socket相关的知识之,有必要系统理解一下Internet相关的一些基础知识. Internet地址 连接到Internet(因特网)的设备称为节点(n ...
- Converts Internet addresses to Internet numbers. ip2long long2ip
http://php.net/manual/en/function.long2ip.phpPHP: ip2long - Manual http://php.net/manual/en/function ...
- 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 ...
- Linux Socket 网络编程
Linux下的网络编程指的是socket套接字编程,入门比较简单.在学校里学过一些皮毛,平时就是自学玩,没有见识过真正的socket编程大程序,比较遗憾.总感觉每次看的时候都有收获,但是每次看完了之后 ...
- [协议]ICMP协议剖析
1.ICMP简介 ICMP全名为(INTERNET CONTROL MESSAGE PROTOCOL)网络控制消息协议. ICMP的协议号为1. ICMP报文就像是IP报文的小弟,总顶着IP报文的名头 ...
随机推荐
- hdu 4685 二分匹配+强连通分量
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4685 题解: 这一题是poj 1904的加强版,poj 1904王子和公主的人数是一样多的,并且给出 ...
- Linux嵌入式系统与硬件平台的关系
一. Linux嵌入式系统 操作系统是一种在计算机上运行的软件,它的主要任务是管理计算机上的系统资源,为用户提供使用计算机及其外部设备的接口.它存在的目的是为了管理所有硬件资源,并且提供应用软件一个合 ...
- [百度空间] [转] 在 Visual C++ 中控制全局对象的初始化顺序
from: http://blog.csdn.net/classfactory/archive/2004/08/07/68202.aspx 在 C++ 中,同一个翻译单位(.cpp文件)里的全局对象的 ...
- int型整数的数值范围
假设int型用两个字节表示对于有符号的整数,用补码表示的话,最高位是符号位,后面15位用来表示数据.1.正数,表示的范围为0000 0000 0000 0001-0111 1111 1111 1111 ...
- Notepad++中常用的插件
Notepad++中常用的插件 Notepad++实用插件分享 otepad++前端开发常用插件介绍
- PHPStorm+PHP5.6+WIN7+IIS7
文件下载 以下为参考网址,如无法打开或变动,请自行搜索,获取最新版本文件请行搜索 PHP Manager:http://www.iis.net/downloads/community/2010/09/ ...
- MySQL中文全文索引插件 mysqlcft 1.0.0 安装使用文档[原创]
[文章+程序 作者:张宴 本文版本:v1.0 最后修改:2008.07.01 转载请注明原文链接:http://blog.zyan.cc/post/356/] MySQL在高并发连接.数据库记录数较多 ...
- c# 发送消息到Email
/// <summary> /// 发送消息到Email /// </summary> /// <param name=&quo ...
- Linux下搭建Android NDK , Linux 驱动开发环境
Eclispe Luna(4.4):http://www.eclipse.org/downloads/ CDT :http://www.eclipse.org/cdt/downloads.php AD ...
- ExtJs之Ext.util.Format
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...