"Codeforces" C. Drazil and factorial

Source: Internet
Author: User

Problem here

Problem

Drazil is playing a math game with Varda.

Let's define for positive an 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 is possibly start with leading zeroes. Then they should find maximum positive number x satisfying following both conditions:

    1. X doesn ' t contain neither digit 0 nor digit 1.

    2. =

Help friends find such number.

INPUT

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 so is larger than 1. Number A may possibly contain leading zeroes.

OUTPUT

Output a maximum possible integer satisfying the conditions above. There should is no zeroes and ones in this number decimal representation.

Sampleinput

4
1234

Output

33222

Input

3
555

Output

555

Solution

Here's the answer.

#include <iostream>#include <string>#include <algorithm>using namespace STD;stringArr[] = {"0","0","2","3","322","5","Only","7","7222","7332"};BOOLcmpChar&a,Char&AMP;B) {returna > B;}intMain () {intNCin>> N;stringInputCin>> input;stringresult =""; for(inti =0; I < input.length (); i++) {if(Input[i]! =' 0 '&& Input[i]! =' 1 ') {result + = arr[input[i]-' 0 ']; }} sort (Result.begin (), Result.end (), CMP);cout<< result << Endl;return 0;}

"Codeforces" C. Drazil and factorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.