首页 新闻 赞助 找找看

怎么将这段代码改写成C++版本的

0
悬赏园豆:10 [待解决问题]

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
using namespace std;
#define inf 0x3f3f3f3f
typedef struct node
{
char x;
struct node *lc,*rc;
}node,*tree;
char pre[100],in[100],post[100];
void topost(char pre[],char in[],char post[],int l)
{
int i;
if(l<=0) return ;
for(i=0;i<l;i++)
if(in[i]==pre[0]) break;
post[l-1]=pre[0];
topost(pre+1,in,post,i);
topost(pre+i+1,in+i+1,post+i,l-1-i);
}
int main ()
{
int i,j,l;
while(gets(pre))
{
gets(in);
l=strlen(pre);
topost(pre,in,post,l);
for(i=0;i<l;i++)
printf("%c",post[i]);
printf("\n");
}
return 0;
}

C++
计算机菜鸟一只的主页 计算机菜鸟一只 | 初学一级 | 园豆:144
提问于:2016-11-27 18:03
< >
分享
所有回答(4)
0

这就是c++好不好,,stl库都用了,,,你如果非要追求c++风格的话,可以吧所有scanf改成cin,把所有printf改成cout....

自为风月马前卒 | 园豆:154 (初学一级) | 2017-02-28 20:47
1

同学你的代码就是C++的,C里面没有带c开头的头文件,并且您的指针都是C++的

个人认为cin, cout很慢,您的代码非常标准C++ ><

Miao_miao | 园豆:202 (菜鸟二级) | 2017-04-14 08:08
0

这本来就是吧。除非你看不到cin和cout不承认。但是cin和cout运行比较慢。scanf和printf很快。

fcyh | 园豆:568 (小虾三级) | 2017-07-04 16:52
0

好吧,这就是C++。scanf和printf虽然是C语言的输入输出流,但是在C++里同样可以使用。

Aehnuwx | 园豆:263 (菜鸟二级) | 2017-12-29 18:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册