• 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
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
  • 相关阅读:
    Redis
    数据库-将一列数据拼接成字符串
    Themida是先进的Windows软件保护系统
    ERC20通证标准是什么?
    低功耗工业RFID设备应用
    【计算机三级信息安全】信息安全保障概述
    三网话费接口API文档
    2024.6.15 英语六级 经验与复盘
    封装系统之新手操作版
    Class类文件中的“咖啡宝贝”
  • 原文地址:https://blog.csdn.net/qq_60775360/article/details/128146002