B. Internet Address codeforces-problem-245B

来源:互联网 发布:qq飞车飞虎雷诺数据 编辑:程序博客网 时间:2024/05/16 17:53
B. Internet Address
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

<protocol>://<domain>.ru[/<context>]

where:

  • <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes),
  • <domain> is a non-empty string, consisting of lowercase English letters,
  • the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters.

If string <context> 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".

理解题意后进行简单的判断,将原字符串分段定位,分批输出即可。

B:#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;int find_useful_r(char *str);int main(){//此代码一直将第一个ru作为.ru输出    char str[51];    scanf("%s",str);    //printf("%d\n",sizeof(str));    if(str[0]=='h')    {        printf("http://");        int locator=find_useful_r(str);        for(int i=4;i<locator;i++)            printf("%c",str[i]);        printf(".ru");        if(strlen(str)>locator+2)//如果".ru"后还有字符        {            printf("/");            for(int i=locator+2;i<strlen(str);i++)                printf("%c",str[i]);        }    }    else//与http仅在第一次循环的初始条件有差异,其余复制    {        printf("ftp://");        int locator=find_useful_r(str);        for(int i=3;i<locator;i++)            printf("%c",str[i]);        printf(".ru");        if(strlen(str)>locator+2)        {            printf("/");            for(int i=locator+2;i<strlen(str);i++)                printf("%c",str[i]);        }    }}int find_useful_r(char *str)//返回第一个可用的'r'的下标{    if(str[0]=='h')    {        for(int i=5;i<strlen(str);i++)            if(str[i]=='r'&&str[i+1]=='u')                return i;    }    else//"ru"前为domain,至少一个字符长度,故跳过协议名后的第一个字符    {        for(int i=4;i<strlen(str);i++)            if(str[i]=='r'&&str[i+1]=='u')                return i;    }}/*注意点:sizeof()返回的是字符串数组的大小而不是实际长度,此题应用strlen()*/




0 0
原创粉丝点击