标签:
#include<iostream> #include<cstdio> using namespace std; struct node { node *lchild; node *rchild; int val; }*root; void dfs(node *p,int tmp) { if(tmp<p->val) { if(p->lchild) dfs(p->lchild,tmp); else { node *t = new node; t->lchild=NULL; t->rchild=NULL; t->val=tmp; p->lchild=t; printf("%d\n",p->val); //printf("lchild %d\n",p->lchild->val); return; } } if(tmp>p->val) { if(p->rchild) dfs(p->rchild,tmp); else { node *t = new node; t->lchild=NULL; t->rchild=NULL; t->val=tmp; p->rchild=t; printf("%d\n",p->val); //printf("rchild %d\n",p->rchild->val); return; } } } int main() { int n,tmp,i; while(~scanf("%d",&n)) { scanf("%d",&tmp); node *t = new node; t->lchild=NULL; t->rchild=NULL; t->val=tmp; root=t; printf("-1\n"); for(i=1; i<n; i++) { scanf("%d",&tmp); dfs(root,tmp); } } return 0; } /************************************************************** Problem: 1467 User: 奔跑的菜鸟 Language: C++ Result: Accepted Time:10 ms Memory:1520 kb ****************************************************************/
#include<iostream> #include<cstdio> using namespace std; int a[10005]; int main() { int n,i,p,len; while(~scanf("%d",&n)) { while(n--) { len=0; scanf("%d",&p); if(p==0) { printf("0\n"); continue; } while(p) { a[len++]=p&1; p>>=1; } for(i=len-1;i>=0;i--) printf("%d",a[i]); printf("\n"); } } return 0; } /************************************************************** Problem: 1473 User: 奔跑的菜鸟 Language: C++ Result: Accepted Time:0 ms Memory:1556 kb ****************************************************************/
标签:
原文地址:http://blog.csdn.net/coraline_m/article/details/51264964