Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这题简单一点的过法,就是直接用strstr函数,有些猥琐直接在原字符串中搜索关键字,如果找到,把找到的位置置0,然后直接输出就好了。当然,修改了原字符串,要记得还原 示意代码如下: p = strstr(source, key) if(p) { // 如果找到关键字,将找到位置设为字符串结尾,设置前要保存 old = *p; *p = '\0'; // 输出字符串 if(p == source)printf("0 NULL\n"); else printf("%d %s\n", strlen(s),s); // 还原之前的改动 *p = old; } // 找不到关键字,直接输出原始串 else printf("%d %s\n", strlen(s), s); Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator