-
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 24, 2022
1 parent
93c75b3
commit 5fcda78
Showing
3 changed files
with
103 additions
and
85 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,11 +1,11 @@ | ||
### 내용 & 질문 | ||
|
||
> 10757 코드 정리를 못하겠고 런타임 에러가 나는 이유를 모르겠습니다.. | ||
> 10757 코드의 어느부분이 틀렸는지 모르겠습니다. 2503번 tc 체크하는 코드를 다시 짤 계획입니다. | ||
### <기존 제출> | ||
|
||
> 2776, 11478, 20291 | ||
> 10757,2503 | ||
### <추가 제출> | ||
|
||
> 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 |
---|---|---|
@@ -1,100 +1,70 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
//더하는 수가 크기 때문에 정수로 입력받으면 안된다. 문자열로 입력받아야한다. | ||
//숫자가 너무 커서 정수형으로 표현하면 오버플로우가 일어날 수 있음. 그래서 문자열로 받아서 자리수 각각마다 더해주기 | ||
//자리가 올라갈 수 있음 ex)13자리 => 14자리 reverse함수 사용해서 받은 값을 거꾸로 저장하기... | ||
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에서 각각 자리수 더해지다가 올라가게 되는 수 저장하기 | ||
int a_size = a.length(), b_size = b.length(); | ||
reverse(a.begin(), a.end()); | ||
reverse(b.begin(), b.end()); | ||
int round; | ||
int result[10000]; | ||
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])); | ||
} | ||
} | ||
result[0] = ((int)a[0] + (int)b[0]) % 10; | ||
round = ((int)a[0] + (int)b[0]) / 10; | ||
for (int i = 1; i < a_size; i++) { | ||
if (i <= b_size) { | ||
result[i] = ((int)a[i] + (int)b[i] + round) % 10; | ||
round = ((int)a[i] + (int)b[i] + round) / 10; | ||
} | ||
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])); | ||
} | ||
} | ||
result[i] = ((int)a[i] + round) % 10; | ||
round = ((int)a[i] + round) / 10; | ||
} | ||
} | ||
if (result[a_size] > 0) { | ||
reverse(result, result + a_size); | ||
for (int i = 0; i < (a_size + 1); i++) { | ||
cout << result[i]; | ||
} | ||
} | ||
else { | ||
reverse(result, result + a_size - 1); | ||
for (int i = 0; i < (a_size); i++) { | ||
cout << result[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])); | ||
} | ||
} | ||
result[0] = ((int)a[0] + (int)b[0]) % 10; | ||
round = ((int)a[0] + (int)b[0]) / 10; | ||
for (int i = 1; i < b_size; i++) { | ||
if (i <= a_size) { | ||
result[i] = ((int)a[i] + (int)b[i] + round) % 10; | ||
round = ((int)a[i] + (int)b[i] + round) / 10; | ||
} | ||
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])); | ||
} | ||
} | ||
result[i] = ((int)b[i] + round) % 10; | ||
round = ((int)b[i] + round) / 10; | ||
}; | ||
} | ||
if (result[b_size] > 0) { | ||
reverse(result, result + b_size); | ||
for (int i = 0; i < (b_size + 1); i++) { | ||
cout << result[i]; | ||
} | ||
} | ||
else { | ||
reverse(result, result + b_size - 1); | ||
for (int i = 0; i < (b_size); i++) { | ||
cout << result[i]; | ||
} | ||
} | ||
} | ||
cout << result; | ||
|
||
//result의 크기가 10000이기 때문에.. 그대로 출력하면 안됨... | ||
|
||
} |
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,48 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
int main() { | ||
int N; | ||
cin >> N; | ||
int tc[100]; | ||
int strike[100]; | ||
int ball[100]; | ||
int cnt = 0; | ||
int h, t, o, th, tt, to; | ||
bool flag[900] = { false, };//숫자와 맞는지 확인할 배열 | ||
for (int i = 0; i < N; i++) { | ||
int test_strike = 0, test_ball = 0; | ||
cin >> tc[i] >> strike[i] >> ball[i]; | ||
h = tc[i] / 100; | ||
t = (tc[i] % 100) / 10; | ||
o = tc[i] - 100 * h - 10 * t; | ||
for (int j = 0; j < 900; j++) { | ||
th = (j + 100) / 100; | ||
tt = ((j + 100) % 100) / 10; | ||
to = (j + 100) % 10; | ||
if (th == tt || th == to || tt == to || tt == 0 || to == 0) { //0이 있거나 각 자리수가 같으면 세지 않음 | ||
flag[j] = false; | ||
continue; | ||
} | ||
if (th == h) test_strike++; //같은지 확인하는 건데... 이부분이 잘못된 것 같음 | ||
else if (th == t) test_ball++; | ||
else if (th == o) test_ball++; | ||
if (tt == t) test_strike++; | ||
else if (tt == h) test_ball++; | ||
else if (tt == o) test_ball++; | ||
if (to == o) test_strike++; | ||
else if (to == h) test_ball++; | ||
else if (to == t) test_ball++; | ||
if (test_ball == ball[i] && test_strike == strike[i]) { //지금 확인한 ball과 strike 개수가 입력받은 수랑 같으면 true로 변환... | ||
flag[j] = true; | ||
} | ||
else { | ||
flag[j] = false; | ||
} | ||
} | ||
} | ||
for (int i = 0; i < 900; i++) { | ||
if (flag[i]) cnt++; | ||
} | ||
cout << cnt; | ||
} |