tmi이긴 한데 이거 풀 때 카페에서 뭐라는~~거야~~~ 하는 노래 나와서 집중 너무 안 됐다ㅋㅋㅋ
문제 해석하고 있는데 자꾸 웃겼음ㅋㅋㅋ
이 문제는 구현 어떻게 할지 생각 좀 하느라 시간 걸렸다.
보면 숫자를 풀어헤치고 그걸 다시 팩토리얼로 만들면 됐다.
이걸 어떻게 코드로 짜지?? 생각하다가 자리수 하나마다 규칙이 있길래 모든 자리수마다 규칙을 적용했다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
using namespace std;
using i64 = long long;
int main() {
int n;
scanf("%d", &n);
char tmp;
scanf("%c", &tmp);
vector <int> num(8, 0);
int state = 0;
for (int i = 0; i < n; i++)
{
char c;
scanf("%c", &c);
if (c != '0')
state = 1;
if (state == 1)
{
if (c == '2')
{
num[2]++;
}
else if (c == '3')
{
num[3]++;
}
else if (c == '4')
{
num[2] += 2;
num[3]++;
}
else if (c == '5')
{
num[5]++;
}
else if (c == '6')
{
num[3]++;
num[5]++;
}
else if (c == '7')
{
num[7]++;
}
else if (c == '8')
{
num[7]++;
num[2] += 3;
}
else if (c == '9')
{
num[2]++;
num[7]++;
num[3] += 2;
}
}
}
for (int i = 7; i > 1; i--)
{
for (int j = 0; j < num[i]; j++)
{
printf("%d", i);
}
}
return 0;
}
이게 최선일까 생각이 들지만 다른 방법은 모르겠다.
'코드포스' 카테고리의 다른 글
[코드포스 Practice14] E. Balanced Ternary String (0) | 2020.03.14 |
---|---|
[코드포스 Practice14] D. Secret Passwords (0) | 2020.03.14 |
[코드포스 Practice14] B. Find The Bone (0) | 2020.03.13 |
[코드포스 Practice14] A. Cheap Travel (0) | 2020.03.13 |
[코드포스 Practice14] 후기 (0) | 2020.03.13 |