ZOJ 1243 URLs
2016-04-21 19:57
309 查看
查看原题
把字符串先以
我之前直接用一句
关于sccanf的介绍
题意
字符串分离思路
用sscanf实现分离,事实上也可以用string数组老老实实挑出分隔符,逻辑我处理不好,换成sscanf了。把字符串先以
://分成两部分,对后面分别进行处理。
我之前直接用一句
sscanf(s,"%[a-zA-Z]://%[a-z,.,-]:%[0-9]/%[a-z,.,-]",protocol,host,port,path);到了第三例的时候崩了,同学提醒这样写表示里面的符号必需,所以是会出错的。以后注意。
关于sccanf的介绍
代码
#include<iostream> #include<stdio.h> #include<string> #include<string.h> using namespace std; int main(){ int n; cin>>n; char s[61]={'\0'}; for(int i=1;i<=n;i++){ cin>>s; char protocol[60]={'\0'}, host[60]={'\0'}, port[60]={'\0'}, path[60]={'\0'}, temp[60]={'\0'}, temp1[60]={'\0'}; cout<<"URL #"<<i<<endl; sscanf(s,"%[a-zA-Z]://%s",protocol,temp); sscanf(temp,"%[^/]/%s",temp1,path); sscanf(temp1,"%[^:]:%s",host,port); if(!strcmp(protocol,"")) cout<<"Protocol = <default>"<<endl; else cout<<"Protocol = "<<protocol<<endl; if(!strcmp(host,"")) cout<<"Host = <default>"<<endl; else cout<<"Host = "<<host<<endl; if(!strcmp(port,"")) cout<<"Port = <default>"<<endl; else cout<<"Port = "<<port<<endl; if(!strcmp(path,"")) cout<<"Path = <default>"<<endl; else cout<<"Path = "<<path<<endl; cout<<endl; } return 0; }
相关文章推荐
- 最小路径覆盖和最小边覆盖及相关性质
- bzoj 2310: ParkII
- 【笔记】android 多线程同步实现方法
- 你最喜欢做什么--兴趣问题清单
- Eclipse取得路径的方法
- map的用法
- 去除ios移动端alert/confirm的网址(url)
- android自定义loding view(下)
- Angular JS 基础
- 程序员可以干多少年?
- Oracle 官方文档学习之 Cursor(Implicit,Explicit)教程(上)
- TreeSet详解
- matlab_最小二乘法数据拟合
- OpenCv学习笔记(一)--OpenCv中Mat类源码的详细解读(1)
- 第一次冲刺阶段(四)
- 抽取、转换和装载介绍(七)管理ETL环境(待续)
- 1008猜数字
- 一个好的产品的几个标准
- 冒泡排序法
- 移动页面自适应手机屏幕宽度