[algorithm] 백준 2752번 세수정렬
·
algorithm/기초 코드
우선 필자는 배열을 선언하고 입력받은 값을 배열 인덱스에 할당해준 후 for문을 활용하여 출력하는 방식으로코드를 짰다. #include #include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); int a; int arr[3] = {}; for (int tmp = 0; tmp > a; arr[tmp] = a; } sort(arr, arr+3); for (int b : arr) { cout 다른 분들의 풀이를 확인해봤더니 배열을 선언하지 않고도 풀 수 있는 재미있는 방법이 있었다// Authored by ..
[algorithm] 백준 9498번 시험 성적
·
algorithm/기초 코드
풀이 : if 문을 사용하면 되는 간단한 문제로 c++은 파이썬과 달리 90 사용이 불가능하기때문에 && 연산자를 이용하여 따로따로 써주어야 함을 주의해야한다. 코드#include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); int a; cin >> a; if (90
[algorithm] 백준 10869번 사칙연산
·
algorithm/기초 코드
풀이 : cin을 통해 a와 b를 입력받고 +, - , * , / , % 의 연산자들을 이용하여 출력해주면 된다 코드#include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); int a,b; cin >> a >> b; cout
[algorithm] 백준 10171번 고양이
·
algorithm/기초 코드
풀이 : 역슬래쉬(\) , 큰따옴표(") , 작은따옴표(')를 출력하고 싶으면 앞에 역슬래쉬(\)를 붙이면 출력할 수 있다 코드#include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); cout
[algorithm] 백준 2557번 Hello World
·
algorithm/기초 코드
풀이 : cout을 이용해 Hello World!를 출력하면 된다 코드#include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); cout
[algorithm] 백준 1000번 A+B
·
algorithm/기초 코드
풀이 : cin을 통해 a와 b를 입력받고 + 연산을 통해 합한 값을 출력하면 된다 코드#include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); int a,b; cin >> a >> b; cout
[algorithm] 백준 10871번 x보다 작은수
·
algorithm/기초 코드
풀이 : 이 문제는 두 수 n과 x를 입력받고 for문을 돌면서 입력받는 a 값이 x보다 작으면 출력하도록 설정하면 되는 문제이다. 배열을 만들어서 풀 수도 있는데 비효율적인 것 같아 아래와 같이 풀이했다. 코드#include using namespace std;int main() { ios::sync_with_stdio(0); cin.tie(0); int n,x,a; cin >> n >> x; for (int tmp = 0; tmp > a; if (a