`
风吹过PP好冷
  • 浏览: 36663 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

PAT1038 Recover the Smallest Number

    博客分类:
  • PAT
 
阅读更多

由一道面试题改的   把数组排成最小的数

 

不同之处是这个是直接按字符串处理的

 

Sample Input:

5 32 321 3214 0229 87
Sample Output:
22932132143287

 

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

bool compare(const string& str1, const string &str2)
{
    string s1=str1+str2;
    string s2=str2+str1;
    return s1<s2;
}

void ComArrayMin(int num)
{
    string *pStrArray=new string[num];

    for(int i=0; i<num; i++)
    {
        cin>>pStrArray[i];		
    }

    sort(pStrArray, pStrArray+num, compare);

    string str = "";
    for(int i = 0; i < num; i++)
    {
        str += pStrArray[i];
    }

    int j = 0;
    for ( ;j < str.length(); j++)
    {
        if (str[j] != '0')
        {
            break;
        }
    }
    if (j == str.length())
    {
        str = "0";
    }
    else
    {
        str = str.substr(j, str.length() - j);
    }
    
    cout<<str;

    cout<<endl;

    delete[] pStrArray;

}

int main()
{
    int Num;
    cin>>Num;
    ComArrayMin(Num);
    return 0;
}
 
分享到:
评论

相关推荐

    Recover4all Professional

    Please read the following terms and conditions carefully because they will apply to Your use of both the unregistered and registered versions of the software program Recover4all(tm) Professional and ...

    word recover word recover

    word recover word recover word recover word recover v

    Recover 4 all Pro V2.26

    can recover files that were removed from the recycle bin and also directly deleted files that haven`t been in the recycle bin. Please note that it cannot be told in advance, if a specific file can be ...

    word recover

    word recover word recover word recover word recover word recover

    上尚城配电(一期)_recover_recover_recover.dwg

    上尚城配电(一期)_recover_recover_recover.dwg11111111111111111111111111111111111111111111111111111111

    Nuclear Coffee Recover Passwords keygen

    Nuclear Coffee Recover Passwords 是一款用于备份和恢复计算机系统中安装的软件产品密匙的工具。 失去了微软视窗,微软Office,Nero的,和Adobe或Acronis产品你的产品密钥?或者,也许你的硬盘驱动器崩溃?也许你是...

    oracle恢复工具-FY_Recover_Data

    Recover_Truncate_data.recover_table(tgtowner, tgttable, tgtowner, rectab, tgtowner, rsttab, datadir, datadir, recfile,datadir, copyfile, blksz); end; 第七步:查看输出内容和构造表名: 15:32:...

    7260 recover

    7260 recover

    EASY RECOVER 数据恢复

    一款绿色版本 无毒 反应快的数据恢复工具,

    Fy_Recover_Data压缩包

    存储过程包Fy_Recover_Data 利用Oracle表扫描机制、数据嫁接机制恢复TRUNCATE或者损坏数据的工具包

    recover 文件恢复工具

    recover 是一款免安装的数据恢复软件 简单实用·

    Recover4all-v2.32

    Recover4all® is an easy to use data recovery software that lets you recover (undelete) files that were accidently deleted under Windows. It does not matter, if the files were removed from the recycle...

    The Concept of Recoverable Robustness,Linear Programming Recover

    The Concept of Recoverable Robustness,Linear Programming Recover

    Recover4All Professional

    软件名称:Recover4All Professional 最新版本:2.09 软件授权:汉化破解版本 使用平台:Win95/98/NT/2000/XP 软件简介:  每个人一定都有曾不小心误删文件与目录的经历,要恢复误删的文件,通常是十分 困难的。...

    RecoverMyFiles强大数据文件恢复工具

    RecoverMyFiles Recover My Files可以恢复由于冒失删除的文档,甚至是磁盘格式化后的文件 恢复工具,它可以自定义搜索的文件夹、文件类型,以提高搜索速度及准确性 节约时间。在搜索过程中,提供了大量的信息,包括...

    RecoverMyFiles 破解版

    数据恢复工具 RecoverMyFiles 破解版

    Advanced RAR PASSWORD RECOVER

    这款RAR密码破解软件RAR与上面那个软件有相似之处。同时能进行多个RAR压缩文件的破解——双开就行。可以自己设置爆破的字符集(支持非英文字符)、中断续破。...还提供了估算破解所需要的时间。运行平台与上一样。...

    Recover4all Pro 2.09

    是相当困难的,不妨先试试 Recover 4 all 看看,它能将刚刚所删除的档案找 出来,但必须在 Windows 下所删除的文件,它才能找出并挽救回来。该版本可 以运行于 Win9x/Me/NT/2000/XP 等操作系统下,帮助你在这些操作...

    《UARs For The Cycle Bin In Windows》.pdf

    The user can’t choose the place they recover the file to and can’t see the content of a file in Cycle Bin. HE6—Good Feature The shortcut mean of the Cycle Bin have similar style with other windows...

    recover-the-binary-tree.zip_The Tree

    利用先序,中序遍历恢复二叉树 ,用兴趣的朋友可以看一下

Global site tag (gtag.js) - Google Analytics