ZOJ Problem Set - 1243 URLs

来源:互联网 发布:解封电脑机器码软件 编辑:程序博客网 时间:2024/06/14 08:41

这道题思路容易乱。注意看题。

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){    //freopen("a.txt","r",stdin);    int cas,cnt,i,len;    string str;    cin>>cas;    cnt = 0;    while(cnt < cas)    {        cin>>str;        cout<<"URL #"<<++cnt<<endl;        len = str.size();        cout<<"Protocol = ";        if(str[0] == 'f') cout<<"ftp"<<endl;        else if(str[0] == 'h') cout<<"http"<<endl;        else cout<<"gopher"<<endl;        cout<<"Host     = ";        for(i = 2;i < len;i ++)        if(str[i]=='/'&&str[i-1] == '/') break;        i++;        while(i < len)        {            if(str[i] == '/') break;            if(str[i] == ':') break;            cout<<str[i ++];        }        cout<<endl;        if(i == len){        cout<<"Port     = <default>"<<endl;        cout<<"Path     = <default>"<<endl;        }        else        {            if(str[i] == ':') {                cout<<"Port     = ";                i++;            while(i < len)            {                if(str[i] == '/') break;                cout<<str[i ++];            }            cout<<endl;            if(i < len){                    i++;                    cout<<"Path     = ";            while(i < len) cout<<str[i ++];            cout<<endl;                }                else                cout<<"Path     = <default>"<<endl;            }            else {cout<<"Port     = <default>"<<endl;                if(i < len){                    i++;                    cout<<"Path     = ";            while(i < len) cout<<str[i ++];            cout<<endl;                }                else                cout<<"Path     = <default>"<<endl;            }        }        cout<<endl;    }}