CodeForces - 245B Internet Address

245b internet address
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.

Sample 1
Inputcopy Outputcopy
httpsunrux
http://sun.ru/x
Sample 2
Inputcopy Outputcopy
ftphttprururu
ftp://http.ru/ruru
Note
In the second sample there are two more possible answers: “ftp://httpruru.ru” and “ftp://httpru.ru/ru”.

#include<bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int cnt=0,h=-1,f=-1,r=-1;
    h=s.find("http");
    f=s.find("ftp");
    if(h==string::npos){
        h=s.length()+7;
    }
    if(f==string::npos){
        f=s.length()+7;
    }
    if(f<h&&f!=string::npos){
        cnt=3;
    }else{
        cnt=4;
    }
    r=s.find("ru");
    if(r==h+cnt||r==f+cnt){
        r=s.find("ru",r+1);
    }
    if(h>f&&f!=string::npos){
        cout<<"ftp://";
        for(int i=f+cnt;i<r;i++){
            cout<<s[i];
        }
    }else{
        cout<<"http://";
        for(int i=h+cnt;i<r;i++){
            cout<<s[i];
        }
    }
    cout<<".ru";
    if(r+2!=s.length()){
        cout<<"/";
        for(int i=r+2;i<s.length();i++){
            cout<<s[i];
        }
    }
}

//code by 01100_10111
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值