반응형
문제
https://www.acmicpc.net/problem/10172
10172번: 개
문제 아래 예제와 같이 개를 출력하시오. 입력 출력 예제 입력 1 복사 예제 출력 1 복사 |\_/| |q p| /} ( 0 )"""\ |"^"` | ||_/=\\__|...
www.acmicpc.net
풀이
- 10171 고양이 문제와 비슷한 단순 출력문제이다.
- 역슬래쉬를(\) 출력하려면 print 문에 역슬래쉬(\)를 2번 작성해야함
- 큰따옴표(")를 출력하려면 print 문에 역슬래쉬(\) + 큰따옴표(")를 작성해야함
- 큰따옴표3개 (""")로 감싸주어서 여러줄을 출력할 수 도 있음
- 문자열 양 옆에 "#"을 써줘서 문자열의 이스케이프 문자를 인식하지 않고 출력할 수 있음
소스코드
This file contains 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
print(#""" | |
|\_/| | |
|q p| /} | |
( 0 )"""\ | |
|"^"` | | |
||_/=\\__| | |
"""#) |
This file contains 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
print(""" | |
|\\_/| | |
|q p| /} | |
( 0 )\"\"\"\\ | |
|\"^\"` | | |
||_/=\\\\__| | |
""") |
This file contains 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
print(#"|\_/|"#) | |
print(#"|q p| /}"#) | |
print(#"( 0 )"""\"#) | |
print(#"|"^"` |"#) | |
print(#"||_/=\\__|"#) |
This file contains 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
print("|\\_/|\n|q p| /}\n( 0 )\"\"\"\\\n|\"^\"` |\n||_/=\\\\__|") |
This file contains 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
print("|\\_/|") | |
print("|q p| /}") | |
print("( 0 )\"\"\"\\") | |
print("|\"^\"` |") | |
print("||_/=\\\\__|") |
후기
- 다양한 풀이 방법이 있어서 다 작성해보았는데, """으로 다수의 줄을 가진 문자열로 작성하는 방법, #을 사용하는 방법, 모두 알아둬야 할 것 이다.
반응형
'PS > 백준' 카테고리의 다른 글
[BOJ] 백준 1330 두 수 비교하기 (Swift) (0) | 2022.12.01 |
---|---|
[BOJ] 백준 25083 새싹 (Swift) (0) | 2022.12.01 |
[BOJ] 백준 10171 고양이 (Swift) (0) | 2022.11.30 |
[BOJ] 백준 2588 곱셈 (Swift) (0) | 2022.11.30 |
[BOJ] 백준 10430 나머지 (Swift) (0) | 2022.11.29 |