https://dev-repository.tistory.com/50

문제 링크 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWGsRbk6AQIDFAVW


문제의 저작권은 SW Expert Academy에 있습니다.



#include <iostream>
 
using namespace std;
 
int main(void) {
    int T, N;
 
    cin >> T;
 
    for(int t_case=0; t_case<T; t_case++) {
        cin >> N;
 
        string cards[N];
 
        cout << "#" << t_case+1;
 
        for(int i=0; i<N; i++) {
            cin >> cards[i];
        }
 
        for(int i=0; i<N; i++) {
            if(i%2 == 0) {
                cout << " " << cards[i/2];
            } else if(N%2 == 0){
                cout << " " << cards[N/2 + i/2];
            } else {
                cout << " " << cards[N/2 + 1 + i/2];
            }
        }
 
        cout << "\n";
    }
 
    return 0;
}
cs

문제 링크 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14mbSaAEwCFAYD


문제의 저작권은 SW Expert Academy에 있습니다.



#include <iostream>
#include <stack>
 
using namespace std;
 
int main(void) {
    int length;
    char temp;
    string input;
 
 
    for(int t_case=0; t_case<10; t_case++) {
        string postfix = "";
 
        cin >> length;
        cin >> input;
 
        for(int i=0; i<length; i++) {
            if(input.at(i) == '+') {
                postfix += input.at(++i);
                postfix += '+';
            } else {
                postfix += input.at(i);
            }
        }
 
        int answer = 0;
        for(int i=0; i<length; i++) {
            if(postfix.at(i) != '+')
                answer += (postfix.at(i) - '0');
        }
 
        cout << "#" << t_case+1 << " " << answer << "\n";
    }
 
    return 0;
}
cs

문제 링크 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV140YnqAIECFAYD


문제의 저작권은 SW Expert Academy에 있습니다.



#include <iostream>
#include <string>
 
using namespace std;
 
typedef struct _node {
    char alph;
    int left, right;
} node;
 
node *nodes;
 
void printNodes(int idx) {
    if(nodes[idx].left != -1) {
        printNodes(nodes[idx].left-1);
    }
    cout << nodes[idx].alph;
    if(nodes[idx].right != -1) {
        printNodes(nodes[idx].right-1);
    }
}
 
int main(void) {
    int N;
    int tempInt, tempChar;
 
    for(int t_case=0; t_case<10; t_case++) {
        cin >> N;
 
        nodes = (node*)malloc(sizeof(node)*N);
 
        for(int i=0; i<N; i++) {
            cin >> tempInt;
            cin >> nodes[i].alph;
            if(N >= (i+1)*2) {
                cin >> nodes[i].left;
            } else {
                nodes[i].left = -1;
            }
            if(N > (i+1)*2) {
                cin >> nodes[i].right;
            } else {
                nodes[i].right = -1;
            }
        }
 
        cout << "#" << t_case+1 << " ";
        printNodes(0);
        cout << "\n";
 
        free(nodes);
    }
 
    return 0;
}
cs

문제 링크 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV141J8KAIcCFAYD


문제의 저작권은 SW Expert Academy에 있습니다.



#include #include using namespace std; typedef struct _node { bool isNum; long double num; char op; int lIdx; int rIdx; } node; node *nodes; long double getNum(int idx) { if(nodes[idx].isNum) return nodes[idx].num; else { switch(nodes[idx].op) { case '+': return getNum(nodes[idx].lIdx-1) + getNum(nodes[idx].rIdx-1); break; case '-': return getNum(nodes[idx].lIdx-1) - getNum(nodes[idx].rIdx-1); break; case '*': return getNum(nodes[idx].lIdx-1) * getNum(nodes[idx].rIdx-1); break; case '/': return getNum(nodes[idx].lIdx-1) / getNum(nodes[idx].rIdx-1); break; } } } int main(void) { int T, N; char temp; string tempStr; //cin >> T; T = 10; for(int t_case=0; t_case> N; nodes = (node*)malloc(sizeof(node)*N); for(int i=0; i> tempStr; cin >> tempStr; if(tempStr.at(0) >= '0' & tempStr.at(0) <= '9') { nodes[i].isNum = true; nodes[i].num = stoi(tempStr); //(int)(temp - '0'); } else { nodes[i].isNum = false; nodes[i].op = tempStr.at(0); cin >> nodes[i].lIdx; cin >> nodes[i].rIdx; } } cout << "#" << t_case+1 << " " << (int)getNum(0) << "\n"; free(nodes); } return 0; }

+ Recent posts