Language: C++



#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#define MAX 610005
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
int root;
int *p = new int[MAX];       //    p---|  Unit
int *left2 = new  int[MAX]; // left2 --|--------> T
int *right2 = new int[MAX]; //right2---|
int *key = new int[MAX];     // key----|
  
   
void Init(){
  rep(i,MAX){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}
  
int TREE_MINIMUM(int x){
  while(left2[x] != NIL){
    x = left2[x];
  }
  return x;
}
  
  
int TREE_SUCCESSOR(int x){
  if(right2[x] != NIL)return TREE_MINIMUM(right2[x]);
  int y = p[x];
  while(y != NIL && x == right2[y]){
    x = y;
    y = p[y];
  }
  return y;
}
   
void TREE_DELETE(int z){
  int y,x;
  if(left2[z] == NIL || right2[z] == NIL)y = z;
  else y = TREE_SUCCESSOR(z);
  
  if(left2[y] != NIL)x = left2[y];
  else x = right2[y];
  
  if(x != NIL)p[x]=p[y];
  if(p[y] == NIL)root = x;
  else if(y == left2[p[y]])left2[p[y]] = x;
  else right2[p[y]] = x;
  
  if(y != z)key[z] = key[y];
  
}
  
  
bool SEARCH(int x,int k){
  if(k == key[x])return true;
  if(x == NIL)return false;
  if(k < key[x])return SEARCH(left2[x],k);
  else return SEARCH(right2[x],k);
}
  
   
void TREE_INSERT(int z){
  int y = NIL; 
  int x = root;
   
  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }
   
}
  
int IndexSearch(int x){
  for(int i=0;i<MAX;i++){
    if(key[i] == x)return i;
  }
  return -1;
}
  
  
void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}
   
void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}
   
   
int main(){
  int val;
  string op;
  long long zr;                    
  
   
  scanf("%d",&n);
  Init(); 
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;        
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
    else if(op == "find"){
      scanf("%d",&val);
      if(SEARCH(root,val)){
    printf("yes\n");
      }else{
    printf("no\n");
      }
         
   
    }
    else if(op == "delete"){
      scanf("%d",&val);
      int inthis = IndexSearch(val);
      if(inthis != -1){
      TREE_DELETE(inthis);
      }
    }
  
  }
   
  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;
  
  return 0;
}
 

 
Compile Error Logs: 

You are not authorized to see the message. 
 
 
??????????????? 
Judge: 4/4  C++  CPU: 00.99 sec  Memory: 10000 KB  Length: 2752 B  2012-06-13 11:26  2012-06-13 11:26  
???????????±????????????????????? 
Case # Verdict CPU Time Memory In Out Case Name 
 Case #1: : Accepted  - - 156 B 123 B test_case_1 
 Case #2: : Accepted  - - 388 B 293 B test_case_2 
 Case #3: : Accepted  - - 10991 B 7763 B test_case_3 
 Case #4: : Accepted  - - 7447514 B 7111523 B test_case_4 



 < prev | 1 /  4 | next >      : Accepted        -        - 

 

Judge Input #1 ( in1.txt | 156 B)  Judge Output #1 ( out1.txt | 123 B) 

20
insert 8
insert 2
insert 3
insert 7
print
insert 22
insert 1
print
find 1
find 2
find 3
find 4
find 5
find 6
find 7
find 8
print
delete 3
delete 7
print

  
 2 3 7 8
 8 2 3 7
 1 2 3 7 8 22
 8 2 1 3 7 22
yes
yes
yes
no
no
no
yes
yes
 1 2 3 7 8 22
 8 2 1 3 7 22
 1 2 8 22
 8 2 1 22

 

Comments 
 

 ??\????????§?????? 

 
Categories 
 



 
Free Tags 
 



 

Compiler output:
a.cc:178:12: error: extended character ± is not valid in an identifier
  178 | ???????????±?????????????????????
      |            ^
a.cc:179:6: error: stray '#' in program
  179 | Case # Verdict CPU Time Memory In Out Case Name
      |      ^
a.cc:180:7: error: stray '#' in program
  180 |  Case #1: : Accepted  - - 156 B 123 B test_case_1
      |       ^
a.cc:181:7: error: stray '#' in program
  181 |  Case #2: : Accepted  - - 388 B 293 B test_case_2
      |       ^
a.cc:182:7: error: stray '#' in program
  182 |  Case #3: : Accepted  - - 10991 B 7763 B test_case_3
      |       ^
a.cc:183:7: error: stray '#' in program
  183 |  Case #4: : Accepted  - - 7447514 B 7111523 B test_case_4
      |       ^
a.cc:191:13: error: stray '#' in program
  191 | Judge Input #1 ( in1.txt | 156 B)  Judge Output #1 ( out1.txt | 123 B)
      |             ^
a.cc:191:49: error: stray '#' in program
  191 | Judge Input #1 ( in1.txt | 156 B)  Judge Output #1 ( out1.txt | 123 B)
      |                                                 ^
a.cc:238:4: error: stray '\' in program
  238 |  ??\????????§??????
      |    ^
a.cc:238:13: error: extended character § is not valid in an identifier
  238 |  ??\????????§??????
      |             ^
a.cc:171:1: error: 'Compile' does not name a type
  171 | Compile Error Logs:
      | ^~~~~~~