• 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
  • 相关阅读:
    微软云计算[3]之Windows Azure AppFabric
    中学数学建模书籍及相关的视频等(2022.08.09)
    keras实现深度神经网络,keras实现卷积神经网络
    go语言中的go mod 和包管理工具
    openfeign整合sentinel进行降级
    Python 爬虫中文返回乱码
    OpenCV特征匹配
    logstash 多行合并
    进程信号的保存和处理
    c++之面向对象程序设计
  • 原文地址:https://blog.csdn.net/qq_60775360/article/details/128146002