목록백준기초 (12)
천천히 빛나는
2750. N개의 수가 주어졌을 때, 이를 오름차순으로 정렬하는 프로그램을 작성하시오. #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector num(n); for (int i = 0; i > num[i]; } sort(num.begin(), num.end()); for (int i = 0; i < n; i++) { cout key; j--) { list[j + 1] = list[j]; } list[j + 1] = key; } } int main() { ios::sync_with_stdio(false); c..
https://shine-slowly.tistory.com/35 알고리즘 : 브루트 포스란 브루트 포스(Brute Force)란? Brute : 무식한 + Force : 힘 가능한 모든 경우의 수를 탐색하면서 요구조건에 충족하는 결과를 가져온다 전체를 탐색하기 때문에 전체 탐색, 완전 탐색이라고도 한다. 브루 shine-slowly.tistory.com 브루트 포스에 대한 개념이 아예 없다면 위 포스팅을 간단하게 읽고 오는 것을 추천한다. 2798. 카지노에서 제일 인기 있는 게임 블랙잭의 규칙은 상당히 쉽다. 카드의 합이 21을 넘지 않는 한도 내에서, 카드의 합을 최대한 크게 만드는 게임이다. 블랙잭은 카지노마다 다양한 규정이 있다. 한국 최고의 블랙잭 고수 김정인은 새로운 블랙잭 규칙을 만들어 상근..
https://shine-slowly.tistory.com/33 알고리즘: 시간 복잡도란 본격적으로 시간복잡도 문제를 풀기 전에, 시간 복잡도에 대해 설명하도록 하겠다. 이 설명은 시간복잡도를 들어는 봤으나 정확히 개념을 모르겠거나 까먹은 전공자들이 읽어야 이해가 될 것이 shine-slowly.tistory.com 시간 복잡도를 잘 모르신다면 이 포스팅을 읽는 것을 추천드립니다. 24262. 오늘도 서준이는 알고리즘의 수행시간 수업 조교를 하고 있다. 아빠가 수업한 내용을 학생들이 잘 이해했는지 문제를 통해서 확인해보자. #include using namespace std; int main() { int n; cin >> n; cout
27323. 정수 A, B 가 주어진다. 세로 길이가 A cm, 가로 길이가 B cm 인 아래와 같은 직사각형의 넓이를 cm2 단위로 구하시오. #include using namespace std; int main(){ int a, b; cin >> a >> b; cout > x >> y >> w >> h; cout > y[i]; } if (x[0] == x[1]) { if (y[0] == y[2]) { // 0 가운데 낀거 cout
5086. 두 수가 주어졌을 때, 다음 3가지 중 어떤 관계인지 구하는 프로그램을 작성하시오. #include #include using namespace std; int main() { ios::sync_with_stdio; cin.tie(0); int x, y; while(1) { cin >> x >> y; if (x == 0 && y == 0) break; if (y % x == 0) { cout > k; while (k != count) { i++; if (i > n) { i = 0; break; } if (n % i == 0) { count++; } } cout > n; if (n == -1) break; for (int i = 2; i < n; i++) { if (n % i == 0) { di..
2745. B진법 수 N이 주어진다. 이 수를 10진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를 사용한다. #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string N; int B; int dec = 0; cin >> N >> B; for (int i = 0; i = 'A') && (N[N.length() - i - 1] N >> B; string change =""; whi..
문제 풀이 전, 2차원 배열 동적할당 방법을 소개하도록 하겠다. 행이 n, 열이 m인 2차원 배열이다. int n, m; cin >> n >> m; int** arr = new int* [n]; for (int i = 0; i < m; i++) { arr[i] = new int[m]; } 자바에서 소개했던 2차원 배열 모습인데 이렇게 생각하면 된다. 2738. N*M크기의 두 행렬 A와 B가 주어졌을 때, 두 행렬을 더하는 프로그램을 작성하시오. #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; int arr1[101][101] = {0}; int arr2[101][101..
25083. 아래 예제와 같이 새싹을 출력하시오. #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout > num; piece[i] -= num; } for (int i = 0; i < 6; i++) { cout n; for (int i = 1; i str; for (int j = 0; j < str.length(); j++) { int last = j; for (int k = j+1; k < str.length(); k++) { if (str[j] == str[k]) { if (last != k - 1) { group = 0; break; } else { last = k; } } } if (grou..
27866. 단어 S와 정수 i가 주어졌을 때, S의 i번째 글자를 출력하는 프로그램을 작성하시오. #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; int i; cin >> s >> i; cout > s; cout > t; for (int i = 0; i > s; cout n; char* c = new char[n+1]; cin >> c; int sum = 0; for (int i = 0; i < n; i++) { sum += int(c[i]) - '0'; } cout s; int n = s.length(); int location[26];..
10807. 총 N개의 정수가 주어졌을 때, 정수 v가 몇 개인지 구하는 프로그램을 작성하시오. #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, v; cin >> n; int* arr = new int[n]; for (int i = 0; i > arr[i]; } cin >> v; int count = 0; for (int i = 0; i n >> x; int* a = new int[n]; for (int i = 0; i > a[i]; } fo..