Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
bLue 获得了一个字符串,现在他要把这个字符串按照某个分隔符来分割成若干个字符串,你能帮他实现吗?
Input
输入数据有多组(数据组数不超过 100),到 EOF 结束。
每组数据输入一行,格式为 “s c”,其中 s 为一个不含空格且长度不超过 1000 的字符串,表示待分割的字符串;c 为一个不是空格的字符,表示分隔符。
输入数据保证在待分割的字符串中,分隔符至少出现一次且不会出现在字符串开头或末尾,并且不会出现连续多个分隔符的情况。
Output
对于每组数据,输出分割后的字符串,每个字符串占一行。
Sample Input
123,DE ,
0123.a,/45/6.8 /
Sample Output
123
DE
0123.a,
45
6.8
Hint
Source
【2016级《程序设计基础(B)I》期末上机考试-第二场】bLue
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char a[1001],s;
int n,i;
while(~scanf("%s %c",a,&s)) /*多组输入,因为a字符串和
字符s为一行输入,中间用空格隔开,所以不能用gets函数输入a字符串;*/
{
n = strlen(a);
for(i=0;i<n;i++)
{
if(a[i]==s)
printf("\n"); /*如果为分隔符则只输出换行,
不输出分隔符;*/
else printf("%c",a[i]);
}
printf("\n");
}
return 0;
}
运行结果:
123,DE ,
123
DE
0123.a/45/6.8 /
0123.a
45
6.8
^Z
Process returned 0 (0x0) execution time : 27.149 s
Press any key to continue.