码迷,mamicode.com
首页 > Web开发 > 详细

CodeForce-245B-Internet Address

时间:2015-04-04 16:49:55      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:acm   算法   

主要涉及字符串操作

#include <iostream>
#include <string>

using namespace std;

int main(){
    freopen("input.txt","r",stdin);
    string str;
    string str2("ru");
    while(cin>>str)
    {
        int len=str.size();
        int b;               //domain后第一个ru的位置
        int k=str.find(str2);//第一个ru的位置
        //cout<<"k="<<k<<endl;
        if (((k==4)&&str.at(0)==‘h‘)||((k==3)&&str.at(0)==‘f‘))
        {
            //cout<<"k+2="<<k+2<<endl;
            b=str.find(str2,k+2);//由于domain非空,所以需要找到第二个ru
            //cout<<"b2="<<b<<endl;
        }else{
            b=k;
        }

        if (b+2<len)
        {
            str.insert(b+2,"/");
        }
        str.insert(b,".");
        if (str.at(0)==‘f‘)
        {
            str.insert(3,"://");
            cout<<str<<endl;
        }
        else if (str.at(0)==‘h‘)
        {
            str.insert(4,"://");
            cout<<str<<endl;
        }


    }
    return 0;
}

CodeForce-245B-Internet Address

标签:acm   算法   

原文地址:http://blog.csdn.net/li8630/article/details/44873135

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!