字符串分割 SDUT

字符串分割 SDUT

Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

bLue 获得了一个字符串,现在他要把这个字符串按照某个分隔符来分割成若干个字符串,你能帮他实现吗?

Input

输入数据有多组(数据组数不超过 100),到 EOF 结束。

每组数据输入一行,格式为 “s c”,其中 s 为一个不含空格且长度不超过 1000 的字符串,表示待分割的字符串;c 为一个不是空格的字符,表示分隔符。

输入数据保证在待分割的字符串中,分隔符至少出现一次且不会出现在字符串开头或末尾,并且不会出现连续多个分隔符的情况。

Output

对于每组数据,输出分割后的字符串,每个字符串占一行。

Sample Input

123,DE ,
0123.a,/45/6.8 /

Sample Output

扫描二维码关注公众号,回复: 4802869 查看本文章

123
DE
0123.a,
45
6.8

#include<stdio.h>
#include<string.h>
int main()
{
char a[1005],c;
int i,n;
while(~scanf("%s %c",a,&c))
{
n=strlen(a);
for(i=0;i<n;i++)
{
if(a[i]==c)
{
a[i]=’\n’;
}

   }
   for(i=0;i<n;i++)
   {
       printf("%c",a[i]);
   }
   printf("\n");
}

return 0;

}

/***************************************************
User name: jk180233李清璇
Result: Accepted
Take time: 0ms
Take Memory: 148KB
Submit time: 2018-11-22 15:51:00
****************************************************/

猜你喜欢

转载自blog.csdn.net/weixin_43892738/article/details/85708887