题头的话:长按点赞可私我赠送50+本C与C++书籍电子书资源
字符串分隔
【问题描述】
输入两个字符串str和cut。cut由若干个字符构成,其中每个字符均可作为一个分隔字符对str进行分隔。
注意:str和cut中均可以包含空格。如果cut中含有空格,则空格也作为str的分隔字符。
cut中字符不能用减号(系统问题)。
【输入形式】
分两行输入两个字符串str和cut。
【输出形式】
分行输出str被分隔后的各字符串。
【样例输入】(其中“□”代表一个空格)
jfi,dpf.,jfpe&df&jfpf/□□jfoef$djfo□,pe
,.□/&$
【样例输出】
jfi
dpf
jfpe
df
jfpf
jfoef
djfo
pe
【样例说明】
输入字符串str =“jfi,dpf.,jfpe&df&jfpf/□□jfoefKaTeX parse error: Expected 'EOF', got '&' at position 21: …,pe",cut =",.□/&̲”,cut中的每个字符(包括空格)均可作为str的分隔符。
输出结束无换行符。
#include <stdio.h>
#include <string.h>
int main()
{
int i,j,n,m,flag=0;
char str[100],cut[50];
gets(str);
gets(cut);
n=strlen(str);
m=strlen(cut);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(str[i]==cut[j])
{
if(flag==0)
flag=1;
break;
}
}
if(j==m)
if(flag==1)
{
printf("\n%c",str[i]);
flag=0;
}
else
printf("%c",str[i]);
}
return 0;
}