hpuoj1474 zz’s math problem Ⅰ D题

1474: zz’s math problem Ⅰ

时间限制: 3 Sec 内存限制: 32 MB

提交: 126 解决: 38 统计

题目描述

有些人心如花木,皆向阳而生
|《剑来》
zz很喜欢数学,但是他又是一个数学渣,我们称这种生物叫做学渣,
zz又碰到了一个数学小问题,定义一个函数P (x)
例如:P (123) = 1! ∗ 2! ∗ 3! 现在需要找到的就是最大的大于等于x大的数z的函数值和x相等,
即P (z) = P (x) 当然z这个数不能包含1或者0
还请输出最大的符合要求数z(不一定比x大) 

输入

第1行输入T (1 ≤ T ≤ 20)组数据
第2行输入n(1 ≤ n ≤ 100),表示x的数字个数
第3行输入正整数 x

输出

输出最大的z(数据保证x内含大于1的数,所以z必定有解) 

样例输入

2
4
1234
3
555

样例输出

33222
555

提示

第一个样例f(1234) = 1! ∗ 2! ∗ 3! ∗ 4! = 288 = f(33222) 

思路:

学校的oj终于回来啦,开心!!!,当然,这肯定是学长们的努力换来的,不容易啊,致敬学长们!!!

这是也我在oj回来后做的第一道题,其实也是补题罢了,这道题其实很简单,无非是把各种情况判一下,唯一需要注意的是,0和1是不算在内的,所以再把0和1去掉就行啦(场上把所有情况都想到了,就是没有考虑到0,好气呦)

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
char str[1005],num[1005];
bool cmp(char a,char b)
{
    return a > b;
}
int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        int n,pos = 0;
        scanf("%d",&n);
        scanf("%s",str);
        for (int i = 0;i < n;i ++)
        {
            if (str[i] == '0' || str[i] == '1')
                continue;
            else if (str[i] == '4')
                num[pos ++] = '3',num[pos ++] = '2',num[pos ++] = '2';
            else if (str[i] == '6')
                num[pos ++] = '5',num[pos ++] = '3';
            else if (str[i] == '8')
                num[pos ++] = '7',num[pos ++] = '2',num[pos ++] = '2',num[pos ++] = '2';
            else if (str[i] == '9')
                num[pos ++] = '7',num[pos ++] = '3',num[pos ++] = '3',num[pos ++] = '2';
            else
                num[pos ++] = str[i];
        }
        num[pos] = '\0';
        sort(num,num + pos ,cmp);
        printf("%s\n",num);
    }
    return 0;    

猜你喜欢

转载自blog.csdn.net/cloudy_happy/article/details/81280302