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


어려운 문제는 아니고 아이디어만 있다면 간단하게 해결할 수 있다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
 
using namespace std;
int alpha[27];
int main() {
    string input;
    cin >> input;
    for (int i = 0; i < 26; i++)
        alpha[i] = -1;
    for (int i = 0; i < input.length(); i++)
        if(alpha[input[i] - 97== -1)
            alpha[input[i] - 97= i;
    for (int j = 0; j < 26; j++)
        cout << alpha[j] << " ";
    return 0;
}
cs


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


이 문제는 간단한 문제로 배열을 생각하지 못한다면 노가다로 빠질 위험이 있다.(알파벳의 개수는 26개다.)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
 
using namespace std;
 
int alpha[37];
int main() {
    string input;
    cin >> input;
    for (int i = 0; i < input.length(); i++)
        alpha[input[i] - 97]++;
    for (int j = 0; j < 26; j++)
        cout << alpha[j] << " ";
    return 0;
}
cs


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


+ Recent posts