ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 5639 C++ 풀이
    카테고리 없음 2018. 11. 11. 17:22
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <climits>
    using namespace std;
    int buffer[10001];

    // endIndex dos not include
    void printPostFix(int startIndex, int endIndex){
    if (startIndex >= endIndex) return;

    int root = buffer[startIndex];
    int startOfRightSubTree = startIndex + 1;
    for (startOfRightSubTree = startIndex + 1; startOfRightSubTree < endIndex; startOfRightSubTree++){
    if (buffer[startOfRightSubTree] > buffer[startIndex]){
    break;
    }
    }
    printPostFix(startIndex + 1, startOfRightSubTree);
    printPostFix(startOfRightSubTree, endIndex);
    cout << root << '\n';
    }

    int main(){
    cin.tie(NULL);
    ios::sync_with_stdio(false);

    int n = 0;
    // cin >> n;
    // for (auto i = 0; i < n; i ++){
    // cin >> buffer[i];
    // }
    // while (!cin.eof()){
    // cin >> buffer[n];
    // n++;
    // }

    string line;
    while (getline(cin, line)){
    buffer[n] = stoi(line);
    n++;
    }
    printPostFix(0, n);

    return 0;

    }


Designed by Tistory.