10-1. 在字符串中查找指定字符(15)
时间限制
400 ms
内存限制
32000 kB
代码长度限制
8000 B
判题程序
Standard
作者
白洪欢(浙江大学)
输入一个字符串S,再输入一个字符c,要求在字符串S中查找字符c。如果找不到则输出“Not found”;若找到则输出字符串S中从c开始的所有字符。
输入格式:
输入在第1行中给出一个不超过80个字符长度的、以回车结束的非空字符串;在第2行中给出一个字符。
输出格式:
在一行中按照题目要求输出结果。
输入样例1:It is a black box b输出样例1:
black box输入样例2:
It is a black box B输出样例2:
Not found
#include<stdio.h> #include<string.h> int main(void) { char str[80]; int i=0; while((str[i]=getchar())!='\n' && i<80){ i++; } str[i]='\0'; char c; scanf("%c",&c); char *p=str; while(*p!='\0'){ if(*p==c){ printf("%s\n",p); break; } p++; } if(*p=='\0'){ printf("Not found\n"); } return 0; }