C - Internet Address CodeForces - 245B(有些思维的水题)

Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:

?/.ru[/]
where:

can equal either “http” (without the quotes) or “ftp” (without the quotes),
is a non-empty string, consisting of lowercase English letters,
the / part may not be present. If it is present, then is a non-empty string, consisting of lowercase English letters.
If string isn’t present in the address, then the additional character “/” isn’t written. Thus, the address has either two characters “/” (the ones that go before the domain), or three (an extra one in front of the context).

When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn’t write characters “:”, “/”, “.”.

Help Vasya to restore the possible address of the recorded Internet resource.

Input
The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only.

It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above.

Output
Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them.

Examples
Input
httpsunrux
Output
http://sun.ru/x
Input
ftphttprururu
Output
ftp://http.ru/ruru
Note
In the second sample there are two more possible answers: “ftp://httpruru.ru” and “ftp://httpru.ru/ru”.
这个题很好懂,注意一些细节就好了。有一些细节想不到。
代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

char s[52];
char ss[52];
int main()
{
	while(scanf("%s",s)!=EOF)
	{
		int flag=0;
		memset(ss,'\0',sizeof(ss));
		int len=strlen(s);
		int cnt=0;
		for(int i=0;i<len;)
		{
			if(i==0)
			{
				if(s[i]=='h'&&s[i+1]=='t'&&s[i+2]=='t'&&s[i+3]=='p')
				{
					printf("http://");
					i+=4;
					continue; //这里wa了一次,没有加这个结果和应该输出的不一样
				}
				if(s[i]=='f'&&s[i+1]=='t'&&s[i+2]=='p')
				{
					printf("ftp://");
					i+=3;
					continue;//一样
				}
			}
			else
			{
				ss[cnt++]=s[i++];
				if(s[i]=='r'&&s[i+1]=='u')
				{
					ss[cnt]='\0';
					printf("%s.ru",ss);
					if((i+1)!=(len-1)) printf("/");//!!!!!httpcsdfvdru这样的样例应该输出htt://pcsdfvd.ru而不是htt://pcsdfvd.ru/
					i+=2;
					while(i<len)
					printf("%c",s[i++]);//上面的执行完了以后就把原来的剩下的输出就好了
					break;//退出
				}
			}
		}
		cout<<endl;
	}
}

努力加油a啊,(o)/~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值