题目描述
题目:输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。
例如,输入”They are students.”和”aeiou”,
则删除之后的第一个字符串变成”Thy r stdnts.”。
输入
输入:
They are students.
aeiou
输出
输出:
Thy r stdnts.
样例输入
They are students.
aeiou
样例输出
Thy r stdnts.
参考代码
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define SEN 100
struct sqstack
{
char *base;
char *top;
int size;
}
;
struct sqstack *initEmptyStack()
/*æ建空è¼*/
{
struct sqstack *p;
p=(struct sqstack *)malloc(sizeof(struct sqstack));
if(p!=NULL)
{
p->base=(char *)malloc(sizeof(struct sqstack)*SEN);
if(p->base!=NULL)
{
p->top=p->base;
p->size=SEN;
return p;
}
} else
free(p);
return NULL;
}
int push(struct sqstack *p,char a)
/*å
¥æ */
{
*p->top++=a;
return 0;
}
int gettop(struct sqstack *p)
/*åæ 顶å
ç´ */
{
if(p->base!=p->top)
return *(p->top-1);
return 0;
}
int pop(struct sqstack *p)
/*åºæ */
{
return *(--p->top);
}
int main()
{
struct sqstack *p,*p1;
char c;
p=initEmptyStack();
p1=initEmptyStack();
while(scanf("%c",&c)&&c!='n')
push(p,c);
while(scanf("%c",&c)!=EOF)
{
while(p->base!=p->top)
{
if(gettop(p)!=c)
push(p1,pop(p));
else {pop(p);}
}
while(p1->base!=p1->top)
push(p,pop(p1));
}
while(p->base!=p->top)
push(p1,pop(p));
while(p1->base!=p1->top)
printf("%c",pop(p1));
printf("n");
return 0;
}
解析
暂无