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


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
#include <iostream>
#include <stdio.h>
#include <deque>
 
#pragma warning (disable : 4996)
using namespace std;
 
int main() {
    deque<int> deq;
    int N, M;
    cin >> N >> M;
    for (int i = 1; i <= N; i++)
        deq.push_back(i);
    printf("<");
    int del;
    while (!deq.empty()) {
        for (int i = 0; i < M; i++) {
            del = deq.front();
            deq.pop_front();
            if (i != M - 1)
                deq.push_back(del);
        }
        if (!deq.empty())
            printf("%d, ", del);
        else
            printf("%d", del);
    }
    printf(">");
 
    return 0;
}
cs


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


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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <cstring>
#include <string>
#include <stack>
 
#pragma warning (disable : 4996)
using namespace std;
 
int main() {
    int N;
    string input;
    stack<char> stack1, stack2;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> input;
        int size1 = input.size();
        for (int j = 0; j < size1; j++) {
            if (input[j] == '<') {
                if (stack1.empty() == 0){
                    char a;
                    a = stack1.top();
                    stack1.pop();
                    stack2.push(a);
                }
            }
            else if (input[j] == '>') {
                if (stack2.empty() == 0){
                    char a;
                    a = stack2.top();
                    stack2.pop();
                    stack1.push(a);
                }
            }
            else if (input[j] == '-') {
                if (stack1.empty() == 0)
                    stack1.pop();
            }
            else
                stack1.push(input[j]);
        }
 
        if (stack1.size() > 0){
            size1 = stack1.size();
            for (int j = 0; j < size1; j++) {
                char a;
                a = stack1.top();
                stack1.pop();
                stack2.push(a);
            }
        }
 
        int size = stack2.size();
        for (int j = 0; j < size; j++) {
            char a;
            a = stack2.top();
            stack2.pop();
            cout << a;
        }
 
        cout << endl;
    }
 
    return 0;
}
cs


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


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
#include <iostream>
 
using namespace std;
 
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) {
        if (b >= c)    cout << b;
        else if (b < c) {
            if (a > c) cout << c;
            else if (a < c) cout << a;
            else if (a == c) cout << a;
        }
    }
    else if (a < b) {
        if (a >= c) cout << a;
        else if (a < c) {
            if (b > c) cout << c;
            else if (b < c) cout << b;
            else if (b == c) cout << b;
        }
    }
    else if (a == b) {
        if (a > c) cout << a;
        else if (a < c) cout << a;
        else if (a == c) cout << a;
    }
    return 0;
}
cs

<Amazing Code From cubelover>

1
2
3
4
b,c;main(a){
    for( ; ~scanf("%d",&a) ; a>b? c=b,b=a : a>c?c=a : 0);
    printf("%d",c);
}
cs


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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <stdio.h>
#include <string>
#pragma warning(disable : 4996)
using namespace std;
 
int main() {
    string input;
    cin >> input;
    int idx = 0;
    int end = input.length();
    while (idx < end) {
        cout << input[idx];
        idx++;
        if (idx % 10 == 0printf("\n");
    }
    printf("\n");
    return 0;
}
cs



<Amazing Code From yunsubaek>

1
main(a){for(;~scanf("%10s",&a);)puts(&a);}
cs
 


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


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
#include <iostream>
#include <stdio.h>
#include <string>
#pragma warning(disable : 4996)
using namespace std;
 
int main() {
    //2007.1.1 MON
    //1,3,5,7,8,10,12 => 31th
    //4,6,9,11 => 30th
    //2 => 28th
    //1/15 2/5 3/5 4/2 5/7 6/4 7/2 8/6 9/3 10/1 11/5 12/3 => MON
    int M, D;
    cin >> M >> D;
    int tmp = 1;
 
    for (int i = 1; i < M; i++) {
        if (i == || i == || i == || i == || i == || i == 10 || i == 12)
            tmp += 31;
        else if (i == || i == || i == || i == 11)
            tmp += 30;
        else if (i == 2)
            tmp += 28;
    }
    tmp += D;
 
    switch (tmp%7){
        case 0cout << "SAT"break;
        case 1cout << "SUN"break;
        case 2cout << "MON"break;
        case 3cout << "TUE"break;
        case 4cout << "WED"break;
        case 5cout << "THU"break;
        case 6cout << "FRI"break;
    }
    return 0;
}
cs


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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <stdio.h>
 
using namespace std;
 
int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - (i+1); j++)
            printf(" ");
        for (int k = 0; k < i + 1; k++)
            printf("*");
        printf("\n");
    }
    return 0;
}
cs


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


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
45
46
47
#include <queue>
#include <stdio.h>
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
    int N;
    cin >> N;
    string input;
    queue<int> q;
    for (int i = 0; i < N; i++) {
        cin >> input;
        if (input == "push") {            //push
            int num;
            cin >> num;
            q.push(num);
            //printf("%d\n", num); No print, if push.
        }
        else if (input == "front") {    //front
            if (q.empty() == 1)
                printf("-1\n");
            else
                printf("%d\n", q.front());
        }
        else if (input == "back") {        //back
            if (q.empty() == 1) {
                printf("-1\n");
            else
                printf("%d\n", q.back());
        }
        else if (input == "size")        //size
            printf("%d\n", q.size());
        else if (input == "pop") {        //pop
            if (q.empty() == 1)
                printf("-1\n");
            else {
                printf("%d\n", q.front());
                q.pop();
            }
        }
        else if (input == "empty")        //empty
            printf("%d\n", q.empty());
    }
    return 0;
}
cs


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


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
#include<iostream>
using namespace std;
 
int main() {
    int input;
    int a = , b = 0;
 
    cin >> input;
 
    if (input == || input == 7) {
        cout << -1;
        return 0;
    }
 
    while (input > 0) {
 
        if (input % == 0) {
            a = input / 5;
            break;
        }
 
        else {
            input = input - 3;
            b++;
        }
    }
    cout << a + b << endl;
}
cs

Problem

Mirko works in a sugar factory as a delivery boy. He has just received an order: he has to deliver exactly N kilograms of sugar 

to a candy store on the Adriatic coast. Mirko can use two types of packages, the ones that contain 3 kilograms, and the ones 

with 5 kilograms of sugar.

Mirko would like to take as few packages as possible. For example, if he has to deliver 18 kilograms of sugar, 

he could use six 3-kilogram packages. But, it would be better to use three 5-kilogram packages, and one 3-kilogram package,

 resulting in the total of four packages.

Help Mirko by finding the minimum number of packages required to transport exactly N kilograms of sugar.

Input

The first and only line of input contains one integer N (3 ≤ N ≤ 5000).

Output

The first and only line of output should contain the minimum number of packages Mirko has to use. If it is impossible 

to deliver exactly N kilograms, output -1.




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


<Method 1>

1
2
3
4
5
6
7
8
9
10
#include <stdio.h>
#pragma warning(disable : 4996)
 
int main() {
    char a;
 
    for (char a; ~scanf("%c"&a); printf("%c", a));
 
    return 0;
}
cs




<Method 2>

1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
#pragma warning(disable : 4996)
 
int main() {
    char a;
 
    while (scanf("%c"&a) != -1)
        printf("%c", a);
 
    return 0;
}
cs


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


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
package javastudy;
 
import java.util.*;
 
public class Main{
    public static void main(String args[]){
        int d[] = new int [10036]; //d(n) of Constructor(n)
 
        for(int n = 1; n < 10001; n++){
            d[dn(n)] = 1;
            if(d[n] != 1System.out.println(n);
        }
    }
    
    static int dn(int i){
        int temp = i;
        if(i >= 10000) {
            temp += i/10000;
            i = i % 10000;
        }
        if(i >= 1000){
            temp += i/1000;
            i = i % 1000;
        }
        if(i >= 100){
            temp += i/100;
            i = i % 100;
        }
        if(i >= 10){
            temp += i/10;
            i = i % 10;
        }
        
        return temp += i;
    }
}
cs


+ Recent posts