티스토리 뷰

반응형


#. Problem

* The copyright in this matter is in BOJ



#. Resolution Process

  1. Read and understand problem

  2. Redefine the problem + abstract

  3. Create solution plan (select Algorithm, Data structure)

  4. Prove the plan (check performance time and usage memory)

  5. Carry out the plan

  6. Look back on the plan and find a way to improve it


#. Python Code

1
2
3
4
5
6
7
8
ML, MR, TL, TR = ["RSP".find(i) for i in input().split()]
 
if ML == MR and (ML + 2) % 3 in [TL, TR]:
    print("TK")
elif TL == TR and (TL + 2) % 3 in [ML, MR]:
    print("MS")
else:
    print('?')
cs


가위바위보 문제를 모듈러 연산을 통해 푸는 방법은 처음 알게 되었다..

역시 문제는 많이 풀어봐야 얻는게 많은 듯 하다..


line 1) 입력된 값을 모듈러에 적용, find()함수 또는 index() 함수 사용

line 3) 민성이가 같은 모양을 내고, 민성이를 이길 수 있는 모양이 태경이에게 있을 경우

line 5) 반대로 태경이가 같은 모양을 내고, 태경이를 이길 수 있는 모양이 민성이에게 있을 경우

line 7) 민성, 태경 모두 다른 모양을 냈을 경우(실수를 하지 않을 경우)


#. C++ Code

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
#include <cstdio>
 
int Change(int x)
{
    if (x == 82)
        return 0;
    else if (x == 83)
        return 1;
    else
        return 2;
}
 
int main(void)
{    
    char a, b, c, d;
    int ML, MR, TL, TR;
 
    scanf("%c %c %c %c"&a, &b, &c, &d);
 
    ML = Change(a);
    MR = Change(b);
    TL = Change(c);
    TR = Change(d);
 
    if (ML == MR && ((ML + 2) % 3 == TL || (ML + 2) % 3 == TR))
        printf("TK\n");
    else if (TL == TR && ((TL + 2) % 3 == ML || (TL + 2) % 3 == MR))
        printf("MS\n");
    else
        printf("?");
 
    return 0;
}
cs


C++ 도 마찬가지로 구현해보았다.

반응형
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday