CodeForces 245B――Internet Address

2014-11-23 19:01:49 · 作者: · 浏览: 3

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

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