![[백준 / BOJ] 2588번 곱셈 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbpOkPl%2FbtrLhuJElLN%2FnIakFo2u5iA3wfUUgQEba1%2Fimg.jpg)
[백준 / BOJ] 2588번 곱셈 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 9. 4. 18:29
반응형
링크 : https://www.acmicpc.net/problem/2588
2588번: 곱셈
첫째 줄부터 넷째 줄까지 차례대로 (3), (4), (5), (6)에 들어갈 값을 출력한다.
www.acmicpc.net
문제

문제 풀이
C++은 수학적으로, 파이썬은 string으로 입력받은 후 인덱싱을 이용해 해결했다.
코드 전문
C++
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
#include <iostream> | |
#include <vector> | |
void init() { | |
std::ios_base::sync_with_stdio(false); | |
std::cin.tie(nullptr); | |
std::cout.tie(nullptr); | |
} | |
int main() { | |
init(); | |
int A, B; | |
std::cin >> A >> B; | |
std::cout << A * (B % 10) << "\n"; //3번에 해당하는 코드 | |
std::cout << A * ((B / 10) % 10) << "\n"; //4번에 해당하는 코드 | |
std::cout << A * (B / 100) << "\n"; //5번에 해당하는 코드 | |
std::cout << A * B << "\n"; //6번에 해당하는 코드 | |
return 0; | |
} |
Python
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
import sys | |
input = sys.stdin.readline | |
if __name__ == "__main__": | |
A, B = input().split() | |
A = int(A) | |
print(A * int(B[2])) | |
print(A * int(B[1])) | |
print(A * int(B[0])) | |
print(A * int(B)) |
소감
다시 풀어보니 파이썬은 인덱싱이 더 편한 것 같아 활용해보았다.
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 10172번 개 (C++, Python) (0) | 2022.09.04 |
---|---|
[백준 / BOJ] 10171번 고양이 (C++, Python) (부제 : 이스케이프 시퀀스) (0) | 2022.09.04 |
[백준 / BOJ] 10430번 나머지 (C++, Python) (0) | 2022.09.04 |
[백준 / BOJ] 3003번 킹, 퀸, 룩, 비숍, 나이트, 폰 (C++, Python) (0) | 2022.09.03 |
[백준 / BOJ] 18108번 1998년생인 내가 태국에서는 2541년생?! (C++, Python) (0) | 2022.09.02 |
@Reo :: 코드 아카이브
자기계발 블로그