zoukankan      html  css  js  c++  java
  • CF Drazil and Factorial (打表)

    Drazil and Factorial
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

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

    Output

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

    Sample test(s)
    input
    4
    1234
    output
    33222
    input
    3
    555
    output
    555



    把2-9每个数打表,看最多能分解成哪几个的阶乘,然后直接替换,最后排序输出。
     1 #include <iostream>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <string>
     6 #include <algorithm>
     7 #include <cctype>
     8 #include <queue>
     9 #include <map>
    10 using    namespace    std;
    11 
    12 const    int    SIZE = 1000;
    13 
    14 bool    comp(const int a,const int b);
    15 
    16 char    RULE[][10] = {{"0"},{"1"},{"2"},{"3"},{"322"},{"5"},{"53"},{"7"},{"7222"},{"7332"}};
    17 int    main(void)
    18 {
    19     int    n;
    20     char    s[SIZE];
    21     char    ans[SIZE] = {''};
    22     
    23     cin >> n;
    24     cin >> s;
    25     for(int i = 0;s[i];i ++)
    26         if(s[i] != '1' && s[i] != '0')
    27             strcat(ans,RULE[s[i] - '0']);
    28     sort(ans,ans + strlen(ans),comp);
    29     cout << ans << endl;
    30 
    31     return    0;
    32 }
    33 
    34 bool    comp(const int a,const int b)
    35 {
    36     return    a > b;
    37 }
  • 相关阅读:
    C#面向对象 类的继承
    C#面向对象 类的封装
    C#面向对象 类
    C#面向对象 1
    盒子模型、网页自动居中、float浮动与清除、横向两列布局
    HTML格式与布局
    HTML表单 CSS样式
    HTML—标签与表格 、框架
    触发器,视图
    while 循环,存储过程
  • 原文地址:https://www.cnblogs.com/xz816111/p/4426382.html
Copyright © 2011-2022 走看看