[#93][알고리즘][SW Expert Academy] 4047. 영준이의 카드 카운팅
[SW Expert Academy] 4047. 영준이의 카드 카운팅
문제 링크(https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIsY84KEPMDFAWN)무작정 풀려고 의식의 흐름대로 코딩했더니 코드가 너무 길어져서
함수만들었따...
C++풀이
#include <iostream>
#include <string>
using namespace std;
bool error;
int Scount, Dcount, Hcount, Ccount, a, i, j, testCase, len;
string str;
void addNumber(bool arr[], string str, bool err) {
if (err != true) {
a = 0;
a = (str.at(j + 1) - '0') * 10 + (str.at(j + 2) - '0');
if (arr[a] == true) {
error = true;
}
else {
arr[a] = true;
}
}
}
void Deck(string str, bool err) {
bool S[14] = { false }, D[14] = { false }, H[14] = { false }, C[14] = { false };
int Scount = 0, Dcount = 0, Hcount = 0, Ccount = 0;
for (j = 0; j < len; j++) {
if (j % 3 == 0) {
//카드 무늬 판별
switch (str.at(j)) {
case 'S':
addNumber(S, str, err);
break;
case 'D':
addNumber(D, str, err);
break;
case 'H':
addNumber(H, str, err);
break;
case 'C':
addNumber(C, str, err);
break;
}
}
}
//출력부분
if (!error) {
for (int k = 1; k <= 13; k++) {
if (S[k] != true) Scount++;
if (D[k] != true) Dcount++;
if (H[k] != true) Hcount++;
if (C[k] != true) Ccount++;
}
//모자란 카드 수 출력
cout << "#" << i << " " << Scount << " " << Dcount << " " << Hcount << " " << Ccount << endl;
}
else {
//중복되는 경우 (error == true)
cout << "#" << i << " " << "ERROR" << endl;
}
}
int main() {
cin >> testCase;
cin.ignore();
for (i = 1; i <= testCase; i++) {
getline(cin, str);
len = str.length();
error = false;
Deck(str, error);
}
return 0;
}
| cs |
댓글
댓글 쓰기