设为首页 加入收藏

TOP

CodeForces 245B――Internet Address
2014-11-23 19:01:49 来源: 作者: 【 】 浏览:1
Tags:CodeForces 245B Internet Address

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

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

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

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

#include 
#include 
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< 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 2093 下一篇模拟红外协议C程序――发送模块

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python 教程 - W3Sch (2025-12-26 12:00:51)
·Python基础教程,Pyt (2025-12-26 12:00:48)
·神仙级python入门教 (2025-12-26 12:00:46)
·“我用Java 8”已成 (2025-12-26 11:19:54)
·下载 IntelliJ IDEA (2025-12-26 11:19:52)