码迷,mamicode.com
首页 > 其他好文 > 详细

*字符串-01. 在字符串中查找指定字符

时间:2014-08-19 23:52:15      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   

 1 /*
 2  * Main.c
 3  * D1-字符串-01. 在字符串中查找指定字符
 4  *  Created on: 2014年8月18日
 5  *      Author: Boomkeeper
 6  *****部分通过******
 7  */
 8 
 9 #include <stdio.h>
10 
11 int mysearch(char ch, const char str[], int length) {
12 
13     int j, ret = -1;
14 
15     for (j = 0; j < length; j++) {
16         if (ch == str[j]) {
17             ret = j;
18             break;
19         }
20     }
21 
22     return ret;
23 }
24 
25 int main() {
26 
27     char S[80] = "\0";
28     char c; //题目中的S和c
29 
30     gets(S);
31     scanf("%c", &c);
32 
33     int flag = mysearch(c, S, sizeof(S) / sizeof(S[0]));
34 
35     if (flag == -1) {
36         printf("Not found\n");
37     } else {
38         int i;
39         for (i = flag; i < sizeof(S) / sizeof(S[0]); i++)
40             printf("%c", S[i]);
41     }
42 
43     return 0;
44 }

 

 bubuko.com,布布扣

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%AD%97%E7%AC%A6%E4%B8%B2-01

 

 

.

*字符串-01. 在字符串中查找指定字符,布布扣,bubuko.com

*字符串-01. 在字符串中查找指定字符

标签:style   blog   http   color   os   io   for   ar   

原文地址:http://www.cnblogs.com/boomkeeper/p/D1.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!