1975-尋找特定字符爲首字母的單詞

【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

發佈了53 篇原創文章 · 獲贊 8 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章