poj 2255 Tree Recovery

strchr()函数
功能就是找出在字符串str中第一次出项字符ch的位置,找到就返回该字符位置的指针(也就是返回该字符在字符串中的地址的位置),找不到就返回空指针
#include<stdio.h>
#include<string.h>
int buildTree(int n,char *a,char *b,char *c)
{
 char *p=b;
 int t;
 if(n<=0) return 0;
 /*while(1)
 {
  if(*a==*p) break;
  else p++;
 }*/
 p=strchr(b,*a);//strchr函数
 t=p-b;
 buildTree(t,a+1,b,c);//a不能忘加1!!!
 buildTree(n-1-t,a+t+1,b+t+1,c+t);
 c[n-1]=*a;
}
int main()
{
 char a[30],b[30],c[30];
 int n,i;
 while(scanf("%s%s",a,b)!=EOF)
 {
  n=strlen(a);
  buildTree(n,a,b,c);
  c[n]='\0';
  printf("%s\n",c);
 }
 return 0;
}

针(就是 null)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值