poj 1577 Falling Leaves

来源:互联网 发布:设计app软件多少钱 编辑:程序博客网 时间:2024/06/04 18:06

非常简单,输入字符串到一个一维数组,然后从字符串的末尾往前

#include <iostream>#include <cstdio>#include <fstream>#include <cstring>#include <string.h>#include <stack>using namespace std;struct nodeT{    char value;    nodeT *left,*right;};nodeT *makeNode(){    nodeT *new_node = new nodeT;    new_node->left = NULL;    new_node->right= NULL;    return new_node;}void find_null(nodeT *root,char s){    if(s<root->value){        if(root->left==NULL)        {            root->left = makeNode();            root->left->value =s;            return;        }        else{            find_null(root->left,s);        }    }    else{        if(root->right==NULL)        {            root->right = makeNode();            root->right->value =s;            return;        }        else{            find_null(root->right,s);        }    }}void front(nodeT *root){    cout<<root->value;    if(root->left){front(root->left);}    if(root->right){front(root->right);}}void function(char senten[5000]){    int posi = strlen(senten) -1;    nodeT *root = makeNode();    root->value = senten[posi];    for(int i=posi-1;i>=0;i--){        find_null( root,senten[i]);    }    front(root);    cout<<endl;}int main(){    //ifstream cin("ha.txt");    int posi=0;    char senten[5000],line[100];    while(cin>>line)    {        if(line[0]!='*'&&line[0]!='$')        {            strcpy(senten+posi,line);            posi+=strlen(line);        }        else        {            posi=0;            //cout<<senten<<endl;            function(senten);            if(line[0]=='$'){return 0;}        }    }}


0 0
原创粉丝点击