반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
Tags
- 2023 Gaming
- 주식
- 1일차
- 112일선
- JavaScript
- GenAI
- 주식단테
- 전주비빔 라이스 버거
- 리팩터링 4장
- 2023 게이밍 인 구글 클라우드
- 언리얼5
- 공부
- 224일선
- 이득우의 언리얼 프로그래밍1
- 작계훈련
- 448일선
- 스즈메의 문단속
- 2023 게이밍
- 이득우의 언리얼 프로그래밍 1
- shader
- 리팩터링 3장
- URP
- 산토리 하이볼
- 언리얼 5
- unity
- 리팩터링
- 상계9동
- 스포일러 주의
- 구글 컨퍼런스
- 2023 구글 클라우드
Archives
- Today
- Total
개발 이야기 안하는 개발자
코딩 테스트 공부_1 본문
반응형
백준 2309번
9개의 숫자는 고정되어 있고, 7개의 숫자를 추출해야한다.
정확하게 합이 100이 되는 숫자를 요청했고, 실패하는 경우는 없다.
그렇다면 2개의 숫자만 알면 되지않을까를 역으로 추적해보았다.
모든 합에 2개의 숫자를 뺐을때 100이되면 정답이라는 생각으로 문제를 풀었다.
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <iostream>
#include <fstream>
#include <stack>
#include <math.h>
#include <string>
#include <climits>
using namespace std;
int N[9] = {};
int TotalSum = 0;
void GetExceptNumber(int& Index_1, int& Index_2)
{
for (int i = 0; i < 8; i++)
{
for (int j = i + 1; j < 9; j++)
{
if (TotalSum - (N[i] + N[j]) == 100)
{
Index_1 = i;
Index_2 = j;
return;
}
}
}
}
int main() {
//Input Reader///////////////////
streambuf* originalCin = cin.rdbuf();
ifstream inputFile("input.txt");
if (!inputFile.is_open()) {
cerr << "파일을 열 수 없습니다." << endl;
return 1;
}
cin.rdbuf(inputFile.rdbuf());
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//////////////////////////////////////
for (int i = 0; i < 9; i++)
{
cin >> N[i];
TotalSum += N[i];
}
sort(N, N + 9);
int ExceptNumber_1 = -1;
int ExceptNumber_2 = -1;
GetExceptNumber(ExceptNumber_1, ExceptNumber_2);
for (int i = 0; i < 9; i++)
{
if (i == ExceptNumber_1 || i == ExceptNumber_2)
{
continue;
}
cout << N[i] << endl;
}
return 0;
}반응형
'개발 > 코딩 테스트' 카테고리의 다른 글
| 코딩 테스트 공부_2 (0) | 2026.01.13 |
|---|