-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sohyundoh
committed
Mar 23, 2022
1 parent
75fc545
commit 93c75b3
Showing
3 changed files
with
202 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
### 내용 & 질문 | ||
> 제출합니다! | ||
|
||
> 10757 코드 정리를 못하겠고 런타임 에러가 나는 이유를 모르겠습니다.. | ||
### <기존 제출> | ||
|
||
> 2776, 11478, 20291 | ||
### <추가 제출> | ||
|
||
> X |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <iostream> | ||
using namespace std; | ||
//더하는 수가 크기 때문에 정수로 입력받으면 안된다. 문자열로 입력받아야한다. | ||
int main() { | ||
string a, b; | ||
string result = 0; | ||
cin >> a >> b; | ||
int a_size = a.length(); | ||
int b_size = b.length(); | ||
int r[10000] = { 0, }; //string에서 각각 자리수 더해지다가 올라가게 되는 수 저장하기 | ||
if (a_size > b_size) { | ||
for (int i = 0; i < a_size; i++) { | ||
if (i > b_size) { //두 숫자의 길이가 다를 경우 | ||
if (i >= 1) { | ||
if ((int)(a[i]) + r[i - 1] >= 10) { | ||
r[i] = ((int)(a[i]) + r[i - 1]) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i]) + r[i - 1]) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i]) + r[i - 1]); | ||
} | ||
} | ||
else { | ||
if ((int)(a[i] + b[i]) >= 10) { | ||
r[i] = ((int)(a[i] + b[i])) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i])) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i])); | ||
} | ||
} | ||
} | ||
else { | ||
if (i >= 1) { | ||
if ((int)(a[i] + b[i]) + r[i - 1] >= 10) { | ||
r[i] = ((int)(a[i] + b[i]) + r[i - 1]) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i]) + r[i - 1]) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i]) + r[i - 1]); | ||
} | ||
} | ||
else { | ||
if ((int)(a[i] + b[i]) >= 10) { | ||
r[i] = ((int)(a[i] + b[i])) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i])) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i])); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
for (int i = 0; i < b_size; i++) { | ||
if (i > a_size) { | ||
if (i >= 1) { | ||
if ((int)(b[i]) + r[i - 1] >= 10) { | ||
r[i] = ((int)(b[i]) + r[i - 1]) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(b[i]) + r[i - 1]) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(b[i]) + r[i - 1]); | ||
} | ||
} | ||
else { | ||
if ((int)(b[i]) >= 10) { | ||
r[i] = ((int)(b[i])) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(b[i])) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(b[i])); | ||
} | ||
} | ||
} | ||
else { | ||
if (i >= 1) { | ||
if ((int)(a[i] + b[i]) + r[i - 1] >= 10) { | ||
r[i] = ((int)(a[i] + b[i]) + r[i - 1]) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i]) + r[i - 1]) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i]) + r[i - 1]); | ||
} | ||
} | ||
else { | ||
if ((int)(a[i] + b[i]) >= 10) { | ||
r[i] = ((int)(a[i] + b[i])) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i])) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i])); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
cout << result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,100 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
int cnt[8001] = { 0, }; // 빈도 카운트하는 배열 | ||
|
||
int findMode() { // 최빈값 찾기 | ||
int max = 0, max_cnt = 0, mode = 0; | ||
for (int i = 0; i < 8001; i++) { | ||
if (max < cnt[i]) { // 최댓값 갱신 | ||
max = cnt[i]; max_cnt = 1; | ||
mode = i - 4000; | ||
} | ||
else if (max == cnt[i]) max_cnt++; // 기존의 최댓값과 동일한 경우 | ||
|
||
// (최빈값이 여러 개인 경우 두번째로 작은 값이 최빈값) | ||
if (max == cnt[i] && max_cnt == 2) mode = i - 4000; | ||
} | ||
return mode; | ||
} | ||
|
||
//더하는 수가 크기 때문에 정수로 입력받으면 안된다. 문자열로 입력받아야한다. | ||
int main() { | ||
int n, sum = 0; | ||
cin >> n; | ||
|
||
vector<int> arr; | ||
arr.assign(n, 0); | ||
|
||
for (int i = 0; i < n; i++) { | ||
cin >> arr[i]; | ||
sum += arr[i]; | ||
cnt[arr[i] + 4000]++; | ||
} | ||
|
||
sort(arr.begin(), arr.end()); // 오름차순 정렬 | ||
|
||
cout << round((double)sum / n) << '\n'; // 산술 평균 | ||
cout << arr[n / 2] << '\n'; // 중앙값 | ||
cout << findMode() << '\n'; // 최빈값 | ||
cout << arr[n - 1] - arr[0]; // 범위 | ||
|
||
return 0; | ||
} | ||
string a, b; | ||
string result = 0; | ||
cin >> a >> b; | ||
int a_size = a.length(); | ||
int b_size = b.length(); | ||
int r[10000] = { 0, }; //string에서 각각 자리수 더해지다가 올라가게 되는 수 저장하기 | ||
if (a_size > b_size) { | ||
for (int i = 0; i < a_size; i++) { | ||
if (i > b_size) { //두 숫자의 길이가 다를 경우 | ||
if (i >= 1) { | ||
if ((int)(a[i]) + r[i - 1] >= 10) { | ||
r[i] = ((int)(a[i]) + r[i - 1]) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i]) + r[i - 1]) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i]) + r[i - 1]); | ||
} | ||
} | ||
else { | ||
if ((int)(a[i] + b[i]) >= 10) { | ||
r[i] = ((int)(a[i] + b[i])) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i])) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i])); | ||
} | ||
} | ||
} | ||
else { | ||
if (i >= 1) { | ||
if ((int)(a[i] + b[i]) + r[i - 1] >= 10) { | ||
r[i] = ((int)(a[i] + b[i]) + r[i - 1]) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i]) + r[i - 1]) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i]) + r[i - 1]); | ||
} | ||
} | ||
else { | ||
if ((int)(a[i] + b[i]) >= 10) { | ||
r[i] = ((int)(a[i] + b[i])) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i])) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i])); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
for (int i = 0; i < b_size; i++) { | ||
if (i > a_size) { | ||
if (i >= 1) { | ||
if ((int)(b[i]) + r[i - 1] >= 10) { | ||
r[i] = ((int)( b[i]) + r[i - 1]) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(b[i]) + r[i - 1]) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(b[i]) + r[i - 1]); | ||
} | ||
} | ||
else { | ||
if ((int)(b[i]) >= 10) { | ||
r[i] = ((int)( b[i])) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(b[i])) % 10; | ||
} | ||
else { | ||
result[i] = ((int)( b[i])); | ||
} | ||
} | ||
} | ||
else { | ||
if (i >= 1) { | ||
if ((int)(a[i] + b[i]) + r[i - 1] >= 10) { | ||
r[i] = ((int)(a[i] + b[i]) + r[i - 1]) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i]) + r[i - 1]) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i]) + r[i - 1]); | ||
} | ||
} | ||
else { | ||
if ((int)(a[i] + b[i]) >= 10) { | ||
r[i] = ((int)(a[i] + b[i])) / 10; // 올라가게 되는 수 정하기 | ||
result[i] = ((int)(a[i] + b[i])) % 10; | ||
} | ||
else { | ||
result[i] = ((int)(a[i] + b[i])); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
cout << result; | ||
} |