![[백준 / BOJ] 10869번 사칙연산 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbFeRgM%2FbtrLakF6bZW%2FZaz6hqJxjCh0Db0XT9xtk0%2Fimg.jpg)
[백준 / BOJ] 10869번 사칙연산 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 9. 1. 19:34
반응형
링크 : https://www.acmicpc.net/problem/10869
10869번: 사칙연산
두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
문제

문제 풀이
앞선 문제들 A + B, A - B, A x B, A / B를 모두 활용하는 문제다.
코드 전문
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> | |
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 << "\n"; | |
std::cout << A - B << "\n"; | |
std::cout << A * B << "\n"; | |
if (B != 0) | |
std::cout << A / B << "\n"; | |
std::cout << A % B << "\n"; | |
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
if __name__ == "__main__": | |
A, B = map(int, input().split()) | |
print(A + B) | |
print(A - B) | |
print(A * B) | |
print(A // B) | |
print(A % B) |
소감
파이썬에서 // 연산자를 활용해야 하는 것이 주의할 점이었다.
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 18108번 1998년생인 내가 태국에서는 2541년생?! (C++, Python) (0) | 2022.09.02 |
---|---|
[백준 / BOJ] 10926번 ??! (C++, Python) (0) | 2022.09.01 |
[백준 / BOJ] 1008번 A/B (C++, Python) (1) | 2022.09.01 |
[백준 / BOJ] 10998번 AxB (C++, Python) (0) | 2022.09.01 |
[백준 / BOJ] 1001번 A-B (C++, Python) (0) | 2022.09.01 |
@Reo :: 코드 아카이브
자기계발 블로그