:: ADVANCE ::

[BaekJoon][2816] 디지털 티비 본문

Algorithm/ES (완전탐색)

[BaekJoon][2816] 디지털 티비

KSJ14 2016. 4. 11. 02:28
반응형

BAEKJOON ONLINE JUDGE


2816번 디지털 티비


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



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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
 
int main()
{
    int n;
    int i = 0, j;
    string ch;
    string temp;
    vector<string> channel;
    string KBS[2= { "KBS1""KBS2" };
 
    scanf("%d", &n);
 
    while (n--) {
        cin >> ch;
        channel.push_back(ch);
    }
 
    for (j = 0; j < 2; j++) {
        if (channel[j] != KBS[j]) {
            if (i == 0 && j > 0) {
                printf("1");
                i++;
            }
            do {
                i++;
                temp = channel[i];
                channel[i] = channel[i - 1];
                channel[i - 1= temp;
                printf("3");
            } while (channel[i - 1!= KBS[j]);
 
            if (i != j + 1) {
                printf("2");
                i--;
 
                while (i > j) {
                    temp = channel[i];
                    channel[i] = channel[i - 1];
                    channel[i - 1= temp;
                    i--;
                    printf("4");
                }
            }
        }
    }
    printf("\n");
 
    return 0;
}
cs


반응형
Comments