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