https://www.acmicpc.net/problem/10828


그리 어려운 문제는 아니고 라이브러리 쓰는 방법을 블로그에 저장용.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <stack>
#include <string>
 
using namespace std;
 
int main() {
    int N;
    stack<int> stack1;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string str;
        cin >> str;
        if (str == "push") {
            int a;
            cin >> a;
            stack1.push(a);
        }
        else if (str == "top") {
            if (stack1.empty() == 1)
                cout << "-1" << endl;
            else
                cout << stack1.top() << endl;
        }
        else if (str == "size")
            cout << stack1.size() << endl;
        else if (str == "empty")
            cout << stack1.empty() << endl;
        else if (str == "pop") {
            if (stack1.empty() == 1) {
                cout << "-1" << endl;
            }
            else {
                cout << stack1.top() << endl;
                stack1.pop();
            }
        }
    }
    return 0;
}
cs


https://www.acmicpc.net/problem/10953


%*c 를 처음봐서 참고용으로 올리게 되었다.

%*c는 입력은 받지만 저장은 안한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstdio>
 
using namespace std;
 
int main() {
    int N, a, b;
    scanf("%d"&N);
    for (int i = 0; i < N; i++) {
        scanf("%1d %*c %1d"&a, &b);
        printf("%d\n", a + b);
    }
    return 0;
}
cs


https://www.acmicpc.net/problem/11722


이 문제는 11053번(https://www.acmicpc.net/problem/11053)에서 부등호만 바꾸면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cstdio>
 
#pragma warning(disable : 4996)
 
using namespace std;
 
int ary[1001];        //array
int lis[1001];        //LIS values
 
int main() {
    int N, input, output;
 
    scanf("%d"&N);
 
    for (int k = 0; k < N; k++) {
        scanf("%d"&input);
        ary[k] = input;
    }
 
    for (int k = 0; k < N; k++) {
        lis[k] = 1;
    }
 
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < i; j++) {
            if (ary[i] < ary[j] && lis[i] < lis[j] + 1) {
                lis[i] = lis[j] + 1;
            }
        }
    }
 
    output = lis[0];
    for (int k = 0; k < N; k++) {
        if (output < lis[k]) {
            output = lis[k];
        }
    }
 
    printf("%d", output);
 
    return 0;
}
cs


+ Recent posts