ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 10866번 C++ 풀이
    백준 2018. 8. 19. 14:53

    #include <iostream>

    #include <cstring>

    #include <algorithm>

    #include <cmath>

    #include <deque>

    using namespace std;

    char buffer[10000000];


    int main() {

    cin.tie(NULL);

    ios::sync_with_stdio(false);


    int n;

    cin >> n;

    deque<int> st;

    for (int i = 0; i< n; i++) {

    cin >> buffer;

    if (strcmp(buffer, "push_front") == 0) {

    int temp;

    cin >> temp;

    st.push_front(temp);

    }

    else if (strcmp(buffer, "push_back") == 0) {

    int temp;

    cin >> temp;

    st.push_back(temp);

    }

    else if (strcmp(buffer, "front") == 0) {

    if (st.empty()) {

    cout << -1 << "\n";

    }

    else {

    cout << st.front() << "\n";

    }

    }

    else if (strcmp(buffer, "size") == 0) {

    cout << st.size() << "\n";

    }

    else if (strcmp(buffer, "pop_front") == 0) {

    if (st.empty()) {

    cout << -1 << '\n';

    }

    else {

    cout << st.front() << "\n";

    st.pop_front();

    }

    }

    else if (strcmp(buffer, "pop_back") == 0) {

    if (st.empty()) {

    cout << -1 << '\n';

    }

    else {

    cout << st.back() << "\n";

    st.pop_back();

    }

    }

    else if (strcmp(buffer, "empty") == 0) {

    if (st.empty()) {

    cout << 1 << '\n';

    }

    else {

    cout << 0 << '\n';

    }


    }

    else if (strcmp(buffer, "back") == 0) {

    if (st.empty()) {

    cout << -1 << "\n";

    }

    else {

    cout << st.back() << "\n";

    }

    }

    }





    return 0;

    }

    '백준' 카테고리의 다른 글

    백준 2579번 C++ 풀이  (0) 2018.08.19
    백준 1463번 C++ 풀이  (0) 2018.08.19
    백준 2748번 풀이  (0) 2018.08.19
    백준 1932번 C++ 풀이  (0) 2018.08.19
    백준 1003번 C++ 풀이  (0) 2018.08.19
Designed by Tistory.