From 1e77bc6e78bdbd3ffd84c9233ed87d77d254c10c Mon Sep 17 00:00:00 2001 From: btothey99 Date: Mon, 7 Mar 2022 22:48:34 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[=EC=A0=95=EB=A0=AC]=203=EC=9B=94=207?= =?UTF-8?q?=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1026.cpp" | 68 +++++++++++++++++++ .../10804.cpp" | 41 +++++++++++ .../11651.cpp" | 39 +++++++++++ .../12840.cpp" | 49 +++++++++++++ .../1758.cpp" | 38 +++++++++++ 5 files changed, 235 insertions(+) create mode 100644 "03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1026.cpp" create mode 100644 "03\354\233\224_04\354\235\274-\354\240\225\353\240\254/10804.cpp" create mode 100644 "03\354\233\224_04\354\235\274-\354\240\225\353\240\254/11651.cpp" create mode 100644 "03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" create mode 100644 "03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1758.cpp" diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1026.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1026.cpp" new file mode 100644 index 0000000..5c60aab --- /dev/null +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1026.cpp" @@ -0,0 +1,68 @@ +#include +#include +#include + +using namespace std; + +// 테스트 결과는 똑같이 나왔으나 백준에선 틀렸다고 나옴 + +void minS(vector &a, vector &b, int n) +{ + //가장 작은 값과 가장 큰 값을 곱하면 최솟값이 나오지 않을까? + //그 다음 작은 값과 그 다음 큰 값을 만나도록 짜려면? + // a를 오름차순으로 정렬한 뒤 b의 가장 큰 값의 인덱스를 찾아 a의 첫 번째 원소부터 짝을 맺게 하면 되지 않을까? + vector tmp1 = a; + vector tmp2 = b; + sort(tmp1.begin(), tmp1.end()); + + int max_a = 0, max_b = 0, max_index = 0, min_index = 0; + int min_a = a[0], min_b = b[0]; + + for (int i = 0; i < n; i++) // a 원소를 순서대로 바꿈 + { + for (int j = 0; j < n; j++) + { + if (max_b < tmp2[j]) + { + max_b = tmp2[j]; + max_index = j; + } + } + + a[max_index] = tmp1[i]; + + tmp2[max_index] = 0; + max_b = 0; + } + + //합 구하기 + int sum = 0; + for (int i = 0; i < n; i++) + { + sum += a[i] * b[i]; + } + + cout << sum; +} + +int main() +{ + //입력 + int n; + cin >> n; + + vector a(n); + vector b(n); + + for (int i = 0; i < n; i++) + { + cin >> a[i]; + } + for (int i = 0; i < n; i++) + { + cin >> b[i]; + } + + //연산 + minS(a, b, n); +} \ No newline at end of file diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/10804.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/10804.cpp" new file mode 100644 index 0000000..99ccffe --- /dev/null +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/10804.cpp" @@ -0,0 +1,41 @@ +#include +#include + +using namespace std; + +vector card; + + +void reverse(int a, int b) +{ + while (a < b) + { + swap(card[a++], card[b--]); + } +} + +int main() +{ + vector a(10, 0); + vector b(10, 0); + + card.assign(20, 0); + + for (int i = 0; i<10 ; i++) { + cin >> a[i] >> b[i]; + } + + for (int i = 0; i < 20; i++) + { + card[i] = i + 1; + } + + for (int i = 0; i<10 ; i++) { + reverse(a[i] - 1, b[i] - 1); + } + + for (int i = 0; i < 20; i++) + { + cout << card[i] << " "; + } +} \ No newline at end of file diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/11651.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/11651.cpp" new file mode 100644 index 0000000..8087df1 --- /dev/null +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/11651.cpp" @@ -0,0 +1,39 @@ +#include +#include +#include + +using namespace std; + +struct coor +{ + int x, y; +}; + +bool cmp(const coor &a, const coor &b){ + if (a.y == b.y) { + return a.x < b.y; + } + return a.y < b.y; +} + + +int main() +{ + int n; + cin >> n; + vector crd(n); + + for (int i = 0; i < n; i++) + { + cin >> crd[i].x >> crd[i].y; + } + + //연산 + sort(crd.begin(), crd.end(), cmp); + + //출력 + for (int i = 0; i < n; i++) + { + cout << crd[i].x <<" "<< crd[i].y << "\n"; + } +} \ No newline at end of file diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" new file mode 100644 index 0000000..5d9d4ac --- /dev/null +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" @@ -0,0 +1,49 @@ +#include +#include + +using namespace std; + +void query(int T, int c, int &total) +{ + if (T == 1) + { + total = total + c; + } + else if (T == 2) + { + total = total - c; + } + else + { + int h_ = total / 3600; + int m_ = total % 3600 / 60; + int s_ = total % 3600 % 60; + cout << h_ << " " << m_ << " " << s_ << "\n"; + } +} + +int main() +{ + //현재 시간 + int h, m, s, total; + cin >> h >> m >> s; + + total = h * 3600 + m * 60 + s; + + //쿼리 개수 + int q; + cin >> q; + + //쿼리 + int T, c; + for (int i = 0; i < q; i++) + { + cin >> T; + if (T != 3) + { + cin >> c; + query(T, c, total); + } + query(T, 0, total); + } +} \ No newline at end of file diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1758.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1758.cpp" new file mode 100644 index 0000000..addee2a --- /dev/null +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1758.cpp" @@ -0,0 +1,38 @@ +#include +#include +#include + +using namespace std; + +int maxTip(int n, vector &tip) +{ + int t; + int max = 0; + for (int i = 0; i < n; i++) + { + t = tip[i] - i; + if (t < 0) + { + t = 0; + } + + max += t; + } + return max; +} + +int main() +{ + int n; + cin >> n; + + vector tip(n, 0); + for (int i = 0; i < n; i++) + { + cin >> tip[i]; + } + + //연산 + sort(tip.begin(), tip.end(), greater<>()); + cout << maxTip(n, tip); +} \ No newline at end of file From a0c7055d0fb24eed14959177f5ca26cfb8160386 Mon Sep 17 00:00:00 2001 From: btothey99 Date: Thu, 10 Mar 2022 22:05:45 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[=EC=A0=95=EB=A0=AC]=203=EC=9B=94=2010?= =?UTF-8?q?=EC=9D=BC=20-=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1026.cpp" | 13 ++++++++----- .../11651.cpp" | 2 +- .../12840.cpp" | 3 +++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1026.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1026.cpp" index 5c60aab..ad1444d 100644 --- "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1026.cpp" +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1026.cpp" @@ -20,19 +20,22 @@ void minS(vector &a, vector &b, int n) for (int i = 0; i < n; i++) // a 원소를 순서대로 바꿈 { - for (int j = 0; j < n; j++) + for (int j = 0; j < n; j++) // b의 최댓값을 찾은 후 a와 매칭 { if (max_b < tmp2[j]) { max_b = tmp2[j]; max_index = j; + } } - + + cout << "max_index : " < Date: Fri, 11 Mar 2022 19:58:32 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[=EC=A0=95=EB=A0=AC]=203=EC=9B=94=2011?= =?UTF-8?q?=EC=9D=BC=20-=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../12840.cpp" | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" index e124fda..8811881 100644 --- "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" @@ -8,12 +8,15 @@ void query(int T, int c, int &total) if (T == 1) { total = total + c; + if ( total >= 86400) { //하루가 넘어감 + total -= 86400; + } } else if (T == 2) { total = total - c; - if ( total < 0){ - total = 0; + if ( total < 0){ //전날로 넘어감 + total = 86400 + total; } } else From f84531d24baac732dbdcfb20247317c02614e43c Mon Sep 17 00:00:00 2001 From: btothey99 Date: Sat, 12 Mar 2022 21:44:03 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[=EC=A0=95=EB=A0=AC]=203=EC=9B=94=2012?= =?UTF-8?q?=EC=9D=BC=20-=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../12840.cpp" | 3 ++- .../1758.cpp" | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" index 8811881..d354790 100644 --- "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/12840.cpp" @@ -9,13 +9,14 @@ void query(int T, int c, int &total) { total = total + c; if ( total >= 86400) { //하루가 넘어감 - total -= 86400; + total = total % 86400; } } else if (T == 2) { total = total - c; if ( total < 0){ //전날로 넘어감 + total = total % 86400; total = 86400 + total; } } diff --git "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1758.cpp" "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1758.cpp" index addee2a..65214ba 100644 --- "a/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1758.cpp" +++ "b/03\354\233\224_04\354\235\274-\354\240\225\353\240\254/1758.cpp" @@ -4,10 +4,15 @@ using namespace std; -int maxTip(int n, vector &tip) +// N <= 100,000 (자연수) +// tip <= 100,000 (자연수) + +//최댓값을 가정해보면 약 150억이 나온다. (맞나요..?) +//int형은 signed int형일 경우 20억(unsigned int는 40억)까지밖에 표현을 못하기 때문에 long long 타입을 사용해야 한다. +long long maxTip(int n, vector &tip) { int t; - int max = 0; + long long max = 0; for (int i = 0; i < n; i++) { t = tip[i] - i;