NOIP1998--拼數(傷心的字符串)



設有n個正整數(n≤20),將它們聯接成一排,組成一個最大的多位整數。

例如:n=3時,3個整數13,312,343聯接成的最大整數爲:34331213

又如:n=4時,4個整數7,13,4,246聯接成的最大整數爲:7424613

輸入輸出格式

輸入格式:

第一行,一個正整數n。

第二行,n個正整數。

輸出格式:

一個正整數,表示最大的整數

樣例:

輸入:

設有n個正整數(n≤20),將它們聯接成一排,組成一個最大的多位整數。

例如:n=3時,3個整數13,312,343聯接成的最大整數爲:34331213

又如:n=4時,4個整數7,13,4,246聯接成的最大整數爲:7424613

輸入輸出格式

輸入格式:

第一行,一個正整數n。

第二行,n個正整數。

輸出格式:

一個正整數,表示最大的整數

輸入輸出樣例

輸入樣例#1:
輸出樣例#1
3                                                                                     
 34331213
13 312 343             



簡單比較字符串,但是但是但但是,千萬別比數字!要連起來比!220和22,數字是220大,但是連起來是22220大 a+b和b+a比,一邊冒泡下來就完事了。



<div>
#include
#include
#include
using namespace std;
string num[22];
int n;


void swap(int x,int y)
{
      string a;
      a=num[x];
      num[x]=num[y];
      num[y]=a;
}


int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
     cin>>num[i];
    for(int i=1;i<=n;i++)
    for(int j=1;j</div>
坑死了,第一次交比的是數字,才80分,淚奔
<pre name="code" class="html" style="color: rgb(81, 81, 81); font-size: 15px; font-weight: bold; line-height: 24px;"><img alt="哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif" /><img alt="哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif" /><img alt="大哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif" /><img alt="大哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif" />
<pre name="code" class="html" style="color: rgb(81, 81, 81); font-size: 15px; font-weight: bold; line-height: 24px;"><img alt="哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif" /><img alt="哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif" /><img alt="大哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif" /><img alt="大哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif" />



設有n個正整數(n≤20),將它們聯接成一排,組成一個最大的多位整數。

例如:n=3時,3個整數13,312,343聯接成的最大整數爲:34331213

又如:n=4時,4個整數7,13,4,246聯接成的最大整數爲:7424613

輸入輸出格式

輸入格式:

第一行,一個正整數n。

第二行,n個正整數。

輸出格式:

一個正整數,表示最大的整數

輸入輸出樣例

輸入樣例#1:
3
13 312 343
輸出樣例#1:
34331213
發佈了30 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章