ZOJ 1243 URLs

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        char str[1000]={'\0'};
        char str2[1000]={'\0'};
        char str3[1000]={'\0'};
        char str4[1000]={'\0'};
        getchar();
        scanf("%[^:/]://%s",str,str2);
        printf("URL #%d\n",i);
        if(strcmp(str,"")!=0)
            printf("Protocol = %s\n",str);
        else
            printf("Protocol = <default>\n");
        sscanf(str2,"%[^/]/%s",str,str3);
        //  str3   path
        sscanf(str,"%[^:]:%s",str2,str4);
        if(strcmp(str2,"")!=0)
            printf("Host     = %s\n",str2);
        else
            printf("Host     = <default>\n");
        if(strcmp(str4,"")!=0)
            printf("Port     = %s\n",str4);
        else
            printf("Port     = <default>\n");
        if(strcmp(str3,"")!=0)
            printf("Path     = %s\n",str3);
        else
            printf("Path     = <default>\n");
        printf("\n");
    }
    return 0 ;
}

你可能感兴趣的:(ZOJ 1243 URLs)