题目:
设有n个正整数,将它们连接成一排,组成一个最大的多位整数。
例如:n=3时,3个整数13,312,343,连成的最大整数为34331213。
又如:n=4时,4个整数7,13,4,246,连成的最大整数为7424613。
输入:
n
输入n个数。
输出:
连成的多位数。
思路:
让这几个数排排序连接成最大的整数,所以应考虑,各个整数顺序,那么对这几个整数排序的准则是什么?
准则:设两个整数是a,b,如果a+b大于b+a,那么a在b的前面,反之,b在a前面也就是局部的解
全局的解就是所有整数的连接顺序,既然要用到连接所以用string。
#include #include#include#include
using namespacestd;string str[3] = {""};string GetStrFromInt(intn)
{
stringstream ss;strings;
ss<
ss>>s;returns;
}string GreedyAlgorithm(intn)
{int arr[4] = { 0};string strmax = "";
cout<< "Please Input the Data:&#