1975-寻找特定字符为首字母的单词

来源:互联网 发布:狮王酵素牙膏知乎 编辑:程序博客网 时间:2024/05/17 01:07

【C系列4.7】函数训练之暗号 1975

Time Limit:  1 s      Memory Limit:   32 MB
Submission:239     AC:121     Score:10.00

 

Description

cyn小朋友今天参加了小学举办的侦探活动,她的任务是从暗号纸条的内容上找出特工Q给出的所有的暗号(即Q开头的单词)

Input

输入一串含有空格的字符串,字符串的长度不超过300。

Output

按顺序每行输出一个找到的首字母为Q或q的单词。

Samples

input:
Queen and quick run from this site
output:
Queen
quick


下附AC代码:
#include <stdio.h>#include <string.h>int main() {char s[303];gets(s);char *str = s;while (1) {str++;if (*str == '\0') {*str = '9';*(++str) = '\0';break;}}str = s;while (*str != '\0') {if ((str == s) && ('q' == *str || 'Q' == *str)) {for (; *str != ' ' && *str != '9'; str++) {printf("%c", *str);}printf("\n");}else if (' ' == *(str - 1) && ('q' == *str || 'Q' == *str)) {for (str; *str != ' ' && *str != '9'; str++) {printf("%c", *str);}printf("\n");}else {str++;}}return 0;}


原题链接:http://acm.hznu.edu.cn/OJ/problem.php?cid=1092&pid=8

阅读全文
1 0
原创粉丝点击