?? 2390477_ac_0ms_16k.c
字號:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INIT (Tree *)malloc(sizeof(Tree))
int n;
char inf[100][100];
typedef struct node
{
char ch;
struct node *l, *r;
}Tree;
Tree *root;
int input()
{
char tmp[100];
n = -1;
while(scanf("%s",tmp)==1)
{
if(tmp[0]=='*')
break;
if(tmp[0]=='$')
return 0;
strcpy(inf[++n],tmp);
}
return 1;
}
void insert(char ch)
{
Tree *s, *p;
s = root;
p = INIT;
p->ch = ch;
p->l = p->r = NULL;
while(s)
{
if(ch>s->ch)
if(s->r)
s = s->r;
else
{
s->r = p;
break;
}
else
if(s->l)
s = s->l;
else
{
s->l = p;
break;
}
}
}
void visit(Tree *a)
{
printf("%c",a->ch);
if(a->l)
visit(a->l);
if(a->r)
visit(a->r);
}
int solve(int com)
{
int i, j;
root = INIT;
root->ch = inf[n][0];
root->l = root->r = NULL;
for(i = n-1; i >= 0; i--)
{
for(j = 0; inf[i][j]!='\0'; j++)
insert(inf[i][j]);
}
visit(root);
printf("\n");
return com;
}
int main()
{
while(solve(input()));
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -