daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. #define INPUT_FILE "check.in"
  5. #define OUTPUT_FILE "check.out"
  6.  
  7. using namespace std;
  8.  
  9. struct tree {
  10.     int value, left, right;
  11. };
  12.  
  13. string check(tree *Tree, int index) {
  14.     string result = "YES";
  15.      
  16.     if (Tree[index].left - 1 > 0) {
  17.         if (Tree[index].value > Tree[Tree[index].left - 1].value) {
  18.             result = check(Tree, Tree[index].left - 1);
  19.         } else result = "NO";
  20.     }
  21.      
  22.     if (Tree[index].right - 1 > 0) {
  23.         if (Tree[index].value < Tree[Tree[index].right - 1].value) {
  24.             result = check(Tree, Tree[index].right - 1);
  25.         } else result = "NO";
  26.     }
  27.      
  28.     return result;
  29. }
  30.  
  31. int main(int argc, const char * argv[]) {
  32.      
  33.     ifstream inputFile(INPUT_FILE);
  34.     ofstream outputFile(OUTPUT_FILE);
  35.      
  36.     int n;
  37.      
  38.     inputFile >> n;
  39.      
  40.     if (n > 0) {
  41.          
  42.         tree *Tree = new tree[n];
  43.          
  44.         for (int i = 0; i < n; i++) {
  45.             inputFile >> Tree[i].value >> Tree[i].left >> Tree[i].right;
  46.         }
  47.          
  48.         outputFile << check(Tree, 0);
  49.          
  50.     } else {
  51.         outputFile << "YES";
  52.     }
  53.      
  54.     inputFile.close();
  55.     outputFile.close();
  56.      
  57.     return 0;
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top