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
 


B. Spotlights
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.

You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.

A position is good if two conditions hold:

  • there is no actor in the cell the spotlight is placed to;
  • there is at least one actor in the direction the spotlight projects.

Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the plan.

The next n lines contain m integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.

Output

Print one integer — the number of good positions for placing the spotlight.

Examples
input
2 4
0 1 0 0
1 0 1 0
output
9
input
4 4
0 0 0 0
1 0 0 1
0 1 1 0
0 1 0 0
output
20
Note

In the first example the following positions are good:

  1. the (1, 1) cell and right direction;
  2. the (1, 1) cell and down direction;
  3. the (1, 3) cell and left direction;
  4. the (1, 3) cell and down direction;
  5. the (1, 4) cell and left direction;
  6. the (2, 2) cell and left direction;
  7. the (2, 2) cell and up direction;
  8. the (2, 2) and right direction;
  9. the (2, 4) cell and left direction.

Therefore, there are 9 good positions in this example.



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
#include <iostream>
#include <stdio.h>
#include <vector>
 
#pragma warning (disable : 4996)
using namespace std;
 
int main() {
    int M, N;
    cin >> M >> N;
    vector<vector<int> > ary(M, vector<int>(N));
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++)
            scanf("%d"&ary[i][j]);
    }
    int result = 0;
    for (int i = 0; i < M; i++) {
        bool cool = false;
        for (int j = 0; j < N; j++) {
            if (ary[i][j] == 1)
                cool = true;
            else if (ary[i][j] == && cool == true)
                result++;
        }    
        cool = false;
        for (int j = N-1; j > -1; j--) {
            if (ary[i][j] == 1)
                cool = true;
            else if (ary[i][j] == && cool == true)
                result++;
        }
    }
    for (int j = 0; j < N; j++) {
        bool cool = false;
        for (int i = 0; i < M; i++) {
            if (ary[i][j] == 1)
                cool = true;
            else if (ary[i][j] == && cool == true)
                result++;
        }
        cool = false;
        for (int i = M - 1; i > -1; i--) {
            if (ary[i][j] == 1)
                cool = true;
            else if (ary[i][j] == && cool == true)
                result++;
        }
    }
    cout << result;
    return 0;
}
cs


A. Interview with Oleg
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.

There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogoogogoogogogo are fillers, but the words googogogogogog and oggo are not fillers.

The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.

To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.

Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!

Input

The first line contains a positive integer n (1 ≤ n ≤ 100) — the length of the interview.

The second line contains the string s of length n, consisting of lowercase English letters.

Output

Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.

Examples
input
7
aogogob
output
a***b
input
13
ogogmgogogogo
output
***gmg***
input
9
ogoogoogo
output
*********
Note

The first sample contains one filler word ogogo, so the interview for printing is "a***b".

The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".


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
#include <iostream>
#include <string>
#include <cstring>
 
#pragma warning (disable : 4996)
using namespace std;
 
int main() {
    int N;
    string S;
    string ans;
    cin >> N >> S;
    int idx = 0;
    while (idx < S.length()) {
        if (S[idx] == 'o' && S[idx + 1== 'g' && S[idx + 2== 'o' ) {
            int tmp = idx + 3;
            while (1) {
                if (S[tmp] == 'g' && S[tmp + 1== 'o')
                    tmp += 2;
                else
                    break;
            }
            idx = tmp;
            ans += "***";
        }
        else {
            ans += S[idx];
            idx++;
        }
    }
 
    cout << ans;
 
    return 0;
}
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.




+ Recent posts