2 seconds
256 megabytes
standard input
standard output
Drazil is playing a math game with Varda.
Let's define for positive integer x as a product of factorials of its digits. For example, .
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number.
The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
4
1234
33222
3
555
555
In the first case,
真的说,这道题目是比较简单的,只是我的想法有点问题。
我做的过程太过于复杂了!在中间操作过程已经使结果超过 long long
而JS相当于在中间过程有简单的优化,是我没想到的,我把每个数还原的过于简单了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <ctype.h>
using namespace std;
#define LL long long int main()
{
int n;
char num[];
int cnt[] = {};
int bit[];
while(scanf("%d%*c", &n) != EOF)
{
int tag = ;
for(int i = ; i < n; i++)
{
scanf("%c", &num[i]);
cnt[num[i] - '']++;
} for(int i = ; i < n; i++)
{
if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
bit[tag++] = ;
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
else if(cnt[] && num[i] == '')
{
bit[tag++] = ;
cnt[]--;
}
}
sort(bit, bit+tag);
for(int i = tag-; i >= ; i--)
{
cout << bit[i];
}
cout << endl;
}
return ;
}