일단 문제를 보면 0~9까지의 숫자카드를 1세트로 계속 받고 6 = 9 이다.
그래서 9를 입력받으면 6배열에 ++해주고
for loop을 하면서 배열에 값을 하나씩 빼줬다.
6은 2개씩 빼줌
for문을 while문으로 감싼 이유는 1세트씩 계속 주기위해서.
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
#include <cstdio> | |
#include <cstring> | |
/** | |
* https://www.acmicpc.net/problem/1475 | |
* BOJ 백준온라인져지 1475 방 번호 풀이 풀이 | |
*/ | |
#define MAX 1111111 | |
#define LENGTH 10 | |
int main(){ | |
char str1[MAX]; | |
int d[LENGTH] = {0}; // 0 ~ 9 {}를 안하면 쓰레기값이 들어가서 안됨 | |
scanf("%s", str1); | |
for(int i = 0, length = strlen(str1); i<length; i++) | |
str1[i]=='9'?d[6]++:d[str1[i]-48]++; | |
int cnt = 0, loop = 1; | |
while(loop){ | |
loop = 0, cnt++, d[6]--; | |
for(int i = 0; i<LENGTH-1; i++){ | |
d[i]--; | |
if(d[i] > 0) loop = 1; | |
} | |
} | |
printf("%d", cnt); | |
return 0; | |
} |
'IT > 알고리즘' 카테고리의 다른 글
BOJ 백준온라인져지 5525 IOIOI 풀이(KMP) (0) | 2017.11.16 |
---|---|
BOJ 백준온라인져지 6064 카잉 달력 풀이 (0) | 2017.11.14 |
BOJ 백준온라인져지 2775 부녀회장이 될테야 풀이 (0) | 2017.11.12 |
BOJ 백준온라인져지 10250 ACM 호텔 풀이 (0) | 2017.11.12 |
BOJ 백준 1011 Fly me to the Alpha Centauri 풀이 Raw (0) | 2017.11.12 |