Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这题简单一点的过法,就是直接用strstr函数,有些猥琐

Posted by Eov_Second at 2016-12-26 14:40:45 on Problem 3753
直接在原字符串中搜索关键字,如果找到,把找到的位置置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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator