Codeforces 515C. Drazil and Factorial

//codeforces 515C. Drazil and Factorial
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

/**
4!=2!*2!*3!
6!=1*2*3*4*5*6=5!*3!
8!=1*2*3*4*5*6*7*8=7!*2!*2!*2!
9!=1*2*3*4*5*6*7*8*9=7!*2!*3!*3!
*/

int main()
{
    char a[20];
    int ch[10] = {0};
    int n;
    cin >> n;
    cin >> a;
    for (int i = 0; i < n; ++i) {
        if (a[i] == '4') {
            ch[2] += 2;
            ++ch[3];
        } else if (a[i] == '6') {
            ++ch[3];
            ++ch[5];
        } else if (a[i] == '8') {
            ++ch[7];
            ch[2] += 3;
        } else if (a[i] == '9') {
            ++ch[7];
            ++ch[2];
            ch[3] += 2;
        } else if (a[i] == '0' || a[i] == '1') {
            continue;
        } else {
            ++ch[a[i] - '0'];
        }
    }
    for (int i = 9; i >= 2; --i) {
        while (ch[i]) {
            putchar(i + '0');
            --ch[i];
        }
    }

    return 0;
}

  只是觉得很神奇的做法,但不太明白为什么……先记下来……

posted @ 2015-06-13 20:28  我不吃饼干呀  阅读(192)  评论(0编辑  收藏  举报