PersonalCorpus 版 (精华区)
寄信人: ooze (烂泥~苦读武侠中)
标 题: 536
发信站: 哈工大紫丁香 (2002年06月19日13:40:29 星期三)
来 源: 202.118.239.224
Your C++ program has solved Ok the problem 536 (Tree Recovery)
in 0.000 seconds with low memory spent.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>
void tryit (char *s,char *t)
{
int i,j,k;
char s1[30],l[30],r[30],root;
if (strlen(s)==0) return;
if (strlen(s)==1) { printf("%c",s[0]); return; }
root=s[0];
i=0; while (t[i]!=root) i++;
t[i]=0;
strcpy(l,t); strcpy(r,t+i+1);
k=0;
for (i=1;i<strlen(s);i++) {
for (j=0;j<strlen(l);j++) if (s[i]==l[j]) break;
if (j<strlen(l)) {
s1[k]=s[i];
k++;
}
}
s1[k]=0;
tryit(s1,l);
k=0;
for (i=1;i<strlen(s);i++) {
for (j=0;j<strlen(r);j++) if (s[i]==r[j]) break;
if (j<strlen(r)) {
s1[k]=s[i];
k++;
}
}
s1[k]=0;
tryit(s1,r);
printf("%c",root);
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\uva\\input536.txt","r",stdin);
freopen("c:\\uva\\output536.txt","w",stdout);
#endif
char s[100],t1[100],t2[100];
int i,j,k;
while (gets(s)!=NULL) {
i=0; while (!isalpha(s[i])) i++;
j=i; while (isalpha(s[j])) j++;
s[j]=0;
strcpy(t1,s+i);
i=j; while (!isalpha(s[i])) i++;
strcpy(t2,s+i);
s[i]=0;
tryit(t1,t2);
printf("\n");
}
}
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.239.224]
--
※ 转寄:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: 202.118.239.224]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.226毫秒