codeforces 515C

题意:

给一个数,把它改写为另一个数,要求这个数最大且每一位阶乘求的和==初始数每一位阶乘求和

输入

3
555

产量

555

纯思维题,画个表:(我也是看了题解才会的......)

2!= 2!

3!= 3!

4!= 3!2!2!

5!= 5!

6!= 5!3!

7!= 7!

8!= 7!2!2!2!

9!= 7!3!3!2!

代码如下:

#include<cstdio>
#include<functional>
#include<algorithm>
#include<string>
#include<string.h>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn = 1e3;
int n;
char x[maxn];
string a[maxn];
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> x[i];
	a[2] = "2";
	a[3] = "3";
	a[4] = "322";
	a[5] = "5";
	a[6] = "53";
	a[7] = "7";
	a[8] = "7222";
	a[9] = "7332";
	string s;
	int t = 1;
	for (int i = n; i >= 1; i--) {
		if (x[i] == '2')s += a[2];
		if (x[i] == '3')s += a[3];
		if (x[i] == '4')s += a[4];
		if (x[i] == '5')s += a[5];
		if (x[i] == '6')s += a[6];
		if (x[i] == '7')s += a[7];
		if (x[i] == '8')s += a[8];
		if (x[i] == '9')s += a[9];
	}
	sort(s.begin(), s.end(),greater<char>());
	cout << s << endl;
	return 0;
}

补:这里说一下string类的排序吧:

sort(s.begin(), s.end(),greater<char>()),这条语句可以对string中的元素进行从大到小排序,greater<char>函数的头文件是:<functional>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值