백준 10430, 2588, 2884, 2741, 2438, 2439

이푸름·2021년 9월 19일
0
post-custom-banner

10430

Python

a, b, c= map(int, input().split())
print((a+b)%c)
print(((a%c) + (b%c))%c)
print((a*b)%c)
print(((a%c) * (b%c)) %c)

C++

#include <iostream>
using namespace std;

int	main(void) {
    int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b) % c << "\n" << ((a % c) + (b % c)) % c << "\n" << (a * b) % c << "\n" << ((a % c) * (b % c)) % c << "\n";
}

2588

Python

a = int(input())
b = input()

a1 = a * int(b[2])
a2 = a * int(b[1])
a3 = a * int(b[0])
a4 = a * int(b)

print (a1, a2, a3, a4, sep='\n')

C++

#include <iostream>
#include <cstdlib>  // atoi 함수 선언된 헤더파일

using namespace std;

int	main(void) {
    int a;
	char b[4];

	cin >> a;
	cin >> b;

	cout << a * (b[2] - '0') << "\n";
	cout << a * (b[2] - '0') << "\n";
	cout << a * (b[2] - '0') << "\n";
	cout << a * atoi(b) << endl;
}

2884

45분 전 알람 설정하기 문제

Python

a, b = map(int, input().split())

if b > 44:
	print(a, b - 45)
elif b < 45 and a > 0:
	print(a - 1, b + 15)
else:
	print (23, b + 15)

C++

#include <iostream>

using namespace std;

int	main(void) {
    int a, b;

	cin >> a >> b;

	if (b >= 45)
		b -= 45;
	else if (a > 0 && b < 45)
	{
		a -= 1;
		b += 15;
	}
	else
	{
		a = 23;
		b += 15;
	}
	cout << a << " " << b << endl;
}

b가 45분일때도 생각해주는 것 잊지 말자.

2741

Python

a = int(input())

for i in range(1, a + 1):
	print(i)

C++

#include <iostream>

using namespace std;

int	main(void) {
    int i, n;

	cin >> n;

	for (i = 1; i <= n; i++)
		cout << i << "\n";
}

2438

Python

a = int(input())

for i in range(1, a + 1):
	print("*" * i)

C++

#include <iostream>

using namespace std;

int	main(void) {
    int n;

	cin >> n;

	for (int i = 0; i < n; i++){
		for(int j = 0; j < i + 1; j++){
			cout<<"*";
		}
		cout << "\n";
	}
}

2439

Python

a = int(input())

for i in range(1, a + 1):
	print(' ' * (a - i), end = '')
	print('*' * i)

C++

#include <iostream>

using namespace std;

int	main(void) {
    int n;

	cin >> n;

	for (int i = 1; i <= n; i++){
		for(int j = i; j < n; j++){
			cout<< ' ';
		}
		for(int k = 1; k <= i; k++){
			cout << '*';
		}
		cout << endl;
	}
	return (0);
}
post-custom-banner

0개의 댓글