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
- ViewBinding Fragment
- 백준 11650
- 안드로이드 공공데이터
- 공공데이터 retrofit
- 좌표 정렬하기2
- 백준 11866
- 좌표 정렬하기
- kotlin retrofit
- 백준
- 백준 11651
- 백준 4949
- Fragment 이동
- 인트로 애니메이션
- 안드로이드 인트로 코틀린
- 수 정렬하기3
- 모각코
- 백준 요세푸스 문제0
- kotlin fragment
- 나이순 정렬
- 공공데이터 kotlin
- 백준 랜선 자르기
- 코틀린 미세먼지
- 백준 1920
- 안드로이드 미세먼지
- 코틀린 공공데이터
- 백준 균형잡힌 세상
- 백준 1837
- 백준 통계
- 안드로이드 인트로 화면
- 백준 암호제작
Archives
- Today
- Total
개발 지식 공유, 복습
모각코 Part 1 본문
#include <bits/stdc++.h>
using namespace std;
int n, k;
int sol(int n, int k){
for(int i=1; i<=n; i++){
//약수 발견시 하나씩 감소
if(n%i ==0){
k--;
if(k==0)
return i;
}
}
return 0;
}
int main(void){
ios::sync
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k;
cout << sol(n, k) << "\n";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, k;
int sol(int n, int k){
for(int i=1; i<=n; i++){
//약수 발견시 하나씩 감소
if(n%i ==0){
k--;
if(k==0)
return i;
}
}
return 0;
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k;
cout << sol(n, k) << "\n";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n, a;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> a;
arr[i] = a;
}
// *max_element와 *min_element로 쉽게 구할 수 있지만, 완전 탐색으로 구현
int min = arr[0];
int max = arr[0];
for (int i = 1; i < n; i++)
{
if (arr[i] < min)
{
min = arr[i];
}
if (arr[i] > max)
{
max = arr[i];
}
}
cout << min << " " << max << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
// 기차에 타고 내린 사람 배열
int in[10], out[10];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int max = 0;
int people = 0;
for (int i = 0; i < 10; i++) {
cin >> in[i] >> out[i];
// 타고 내린 사람 수 계산
people = int[i] - out[i] + people;
최대 사람 수 비교
if (max < people)
max = people;
}
cout << max << endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
// 0 1 1 2 3 5 8 13....
// 재귀로 접근
int fibo(int num) {
if(num == 0)
return 0;
if(num == 1)
return 1;
return fibo(num-2) + fibo(num-1);
}
int num;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> num;
cout << fibo(num) << "\n";
}
#include <bits/stdc++.h>
using namespace std;
int kids[9];
int sum;
pair<int, int> p;
// 조합로 풀이
// 9C7 == 9C2이므로 2개 선택 후 제외
void solve(){
for(int i = 0; i < 9; i++){
for(int j = 0; j < i; j++){
if(sum - kids[i] - kids[j] == 100){
p = {kids[i], kids[j]};
return;
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
for(int i = 0; i < 9; i++){
cin >> kids[i];
sum += kids[i];
}
vector<int> res;
solve();
for(int i = 0; i < 9; i++){
if(p.first == kids[i] || p.second == kids[i])
continue;
res.push_back(kids[i]);
}
sort(res.begin(), res.end());
for(int a : res)
cout << a << "\n";
return 0;
}
7. 최대공약수와 최소공배수 (백준 2609, 브론즈 1)
#include <bits/stdc++.h>
using namespace std;
// 유클리드 호제법 사용
// 최대공약수
int gcd(int a, int b) {
int c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
// 최소공배수
int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
int n1, n2;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n1 >> n2;
cout << gcd(n1, n2) << "\n" << lcm(n1, n2);
}
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int A[10];
int N = 3;
int num = 0;
cin >> num;
for (int i = 0; i < num; i++) {
for (int j = 0; j < 10; j++) {
cin >> A[j];
}
// 한 테스트케이스 씩 정렬 후 N번째 수 출력
sort(A, A + 10);
cout << A[10 - N] << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
int data;
int cnt = 0;
for (int i = 0; i < n; i++)
{
cin >> data;
int j;
// 2 ~ 입력한 값 직전까지 나눠지는 값이 있으면 소수
// 입력값의 제곱근만큼까지 했으면 속도가 더 빨라질 수 있을 듯
for (j = 2; j < data; j++)
{
if (data % j == 0)
break;
}
if (j == data)
cnt++;
}
cout << cnt << "\n";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
// arr[1] = 1, arr[2] = 2, arr[3] = 2, arr[4] = 3... 의 내용을 저장하기 위한 배열
int arr[1001];
int n, m;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int sum = 0, k=1;
// 이중포문으로 arr 배열에 저장
for(int i = 1; i <= 1000; i++){
for(int j = 1; j <= i; j++){
arr[k] = i;
if(k > 1000){
break;
}
k++;
}
}
cin >> n >> m;
// 시작점과 끝점까지 배열에 저장된 값 더하기
for(int i = n; i <= m; i++){
sum += arr[i];
}
cout << ans << "\n";
}
#include <bits/stdc++.h>
using namespace std;
int m, n;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int sum = 0, min = -1;
int cnt = 0;
cin >> m >> n;
for (int i = m; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (i % j == 0)
cnt++;
}
// 소수인 경우
if (cnt == 2) {
// 소수 최초 발견 시, min을 첫번째 발견한 소수로 저장
if (min == -1)
min = i;
sum += i;
}
cnt = 0;
}
// 소수가 없는 경우
if (min == -1)
cout << -1 << '\n';
else
cout << sum << '\n' << min << '\n';
}
'모각코' 카테고리의 다른 글
모각코 Part 6 (0) | 2022.11.30 |
---|---|
모각코 Part 5 (0) | 2022.11.29 |
모각코 Part 4 (1) | 2022.11.13 |
모각코 Part 3 (0) | 2022.11.10 |
모각코 Part 2 (0) | 2022.10.19 |