10-1. 在字符串中查找指定字符(15)

来源:互联网 发布:java迭代器怎么使用 编辑:程序博客网 时间:2024/04/30 23:45

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 boxb
输出样例1:
black box
输入样例2:
It is a black boxB
输出样例2:
Not found
#include <stdio.h>#define STRING_SIZE 80int main(void){char str[STRING_SIZE + 1];char ch;int i=0, flag=0;gets(str);scanf("%c",&ch);while(str[i] != '\0'){//不是字符串的结尾 if(str[i]==ch){flag=1;break;}i++;}if(flag){while(str[i]!='\0'){printf("%c",str[i]);i++; }printf("\n");}else printf("Not found\n");return 0;}


0 0
原创粉丝点击