sscanf的用法—hunnuoj10027

Server
Time Limit: 1000ms, Special Time Limit:2500ms,Memory Limit:32768KB
Total submit users: 66, Accepted users:66
Problem 10027 : No special judgement
Problem description
  

Users of computers frequently enter URLs (Uniform Resource Locators) in the form

    protocol://server.network

For example, in the URL

    http://www.monkey.donkey.zebra.com

the protocol is "http", the server is "www", and the network is "monkey.donkey.zebra.com". For purposes of this problem, the protocol and server are alphanumeric strings, whereas the network is an alphanumeric string that may also contain periods (however, the URL cannot end with a period or contain two consecutive periods).

Input
  Each line of the input contains a URL in the format specified above. No line will be longer than 80 characters. The input is terminated by end-of-file.
Output
  Each line of input will give rise to one line of output, consisting of the word "server", followed by a colon and one blank space, and the server from the corresponding line of input.
Sample Input
http://www.monkey.donkey.zebra.com
ftp://newton.cs.colorado.edu
Sample Output
server: www
server: newton
Problem Source
  HNU Contest 


这道题具体是一道大水题,而且本校的oj人数实在惨不忍睹,先贴一下代码

 
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;

int const SIZE=100;

int main()
{
    char A[SIZE],B[SIZE];
    while(scanf("%s",A)!=EOF)
    {
        sscanf(A,"%*[^/]//%[^.]",B);
        printf("server: %s\n",B);
    }
    return 0;
}

这里的  "%*[^/]" , * 代表不取, [^/] 代表不是 '/' 的所有字符,所以全部意思就是不取前面不是 '/' 的字符

中间的"//"代表分隔符

然后  "%[^.]"  代表所有不是 '.' 的就读入,因为这道题结尾是用 '.'  分隔

具体的更多用法在下面大牛们的链接里

但是打开了sscanf的大门,看了大牛们的讲解,先转载一下

 

http://www.cnblogs.com/gmh915/archive/2009/09/30/1576995.html

这位大牛写的比较清楚,还引用了 另一位大牛的,也贴一下

http://blog.csdn.net/lbird/article/details/1724429


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值