1989-字符串分割

来源:互联网 发布:碟仙是真的吗 知乎 编辑:程序博客网 时间:2024/06/02 04:59

【C系列5.4】指针专题之分割字符串 1989

Time Limit:  1 s      Memory Limit:   32 MB
Submission:241     AC:75     Score:19.88

 

Description

Alex的好朋友都去生猴子了,所以她只好百无聊赖地继续玩字符串游戏。输入一个长度不超过10000的字符串,字符串中只含字母和空格,空格用于分隔单词,请将字符串中用空格分隔的单词输出来。

Input

输入含多组测试数据,每组占一行,是一个长度不超过10000的字符串,只含字母和空格。

Output

将字符串中用空格分隔的单词输出来,每个单词一行。

每组测试数据之间用空行隔开。

Samples

input:
Hello world
output:
Hello
world


下附AC代码:

#include <stdio.h>#include <string.h>int main() {char str[10000];int i, len;while (gets(str) != '\0') {len = 0;while (str[len] != '\0')len++;for (i = 0; i < len; i++) {*str = str[i];if (' ' == *str)printf("\n");elseprintf("%c", *str);}memset(str, 0, sizeof(str));//清空数组printf("\n");printf("\n");}return 0;}


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

原创粉丝点击