[파이썬][백준 10102번] 개표
1. 문제Permalink
[Bronze II] 개표 - 10102Permalink
성능 요약Permalink
메모리: 30840 KB, 시간: 68 ms
분류Permalink
문자열(string)
출처: 백준, https://https://www.acmicpc.net/
2. 해결방법 시간복잡도Permalink
- 단순 코딩
3. 문제 해결 및 코드Permalink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
T = int(sys.stdin.readline()) | |
AB = str(input()) | |
if AB.count("A") > AB.count("B"): | |
print("A") | |
elif AB.count("B") > AB.count("A"): | |
print("B") | |
else: | |
print("Tie") |
-
주석을 참고하면서 이해를 돕습니다.Permalink
4. 알고리즘 및 해설Permalink
- 받아야 될 값은 T로 받는다.
- AB라는 값을 문자열로 받고 해당 문자열에서 찾고자 하는 값을 count()함수를 이용하여 찾는다.
- if문을 통해 경우에 따라 원하는 값을 출력한다.
5. 짚고 넘어가기Permalink
- 문자열에서의 count()함수는 우리가 찾고자 하는 문자값을 쉽게 찾을 수 있다.