數串

數串

題目描述

設有n個正整數,將他們連接成一排,組成一個最大的多位整數。
如:n=3時,3個整數13,312,343,連成的最大整數為34331213。
如:n=4時,4個整數7,13,4,246連接成的最大整數為7424613。

輸入描述:

有多組測試樣例,每組測試樣例包含兩行,第一行為一個整數NN<=100),第二行包含N個數(每個數不超過1000,空格分開)。

輸出描述:

每組數據輸出一個表示最大的整數。

示例1

輸入

2
12 123
4
7 13 4 246

輸出

12312
7424613

題意:n個數,問怎么排連起來表示的數最大。

解題思路:感覺像是按字典序排序,例如70和72,因為72字典序比70大,所以72必放在70前面,然后隨便寫了個排序,沒想到還真過了。

代碼

#include<stdio.h>
#include<iostream>
using namespace std;
#include<string>
#include<algorithm>
#define maxn 105string arr[maxn];
int cmp(string a,string b)
{return (a+b)>(b+a);
}
int main()
{int n;while(~scanf("%d",&n)){for(int i=0; i<n; i++)cin>>arr[i];sort(arr,arr+n,cmp);for(int i=0; i<n; i++)cout<<arr[i];cout<<endl;}return 0;
}

轉載于:https://www.cnblogs.com/RefrainLi/p/8861406.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/278478.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278478.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278478.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

chromebook刷機_如何在Chromebook上拍照

chromebook刷機Your Chromebook comes equipped with a built-in camera you can use to snap pictures to post to your social media accounts or share with friends and family. Here’s how to take a photo on a Chromebook. 您的Chromebook配備了一個內置攝像頭&#xf…

樹和二叉樹簡介

一、樹 1、什么是樹&#xff1f; 樹狀圖是一種數據結構&#xff0c;它是由n&#xff08;n>1&#xff09;個有限節點組成一個具有層次關系的集合。把它叫做“樹”是因為它看起來像一棵倒掛的樹&#xff0c;也就是說它是根朝上&#xff0c;而葉朝下的。它具有以下的特點&#…

對eventloop的研究

javasctipt是一門單線程的非阻塞的腳本語言&#xff0c;單線程意味著&#xff0c;JavaScript 單線程意味著&#xff0c;javascript代碼在執行的任何時候&#xff0c;都只有一個主線程來處理所有的任務。 JavaScript的事件分兩種&#xff0c;宏任務(macro-task)和微任務(micro-t…

【SSH高速進階】——struts2簡單的實例

近期剛剛入門struts2。這里做一個簡單的struts2實例來跟大家一起學習一下。 本例實現最簡單的登陸&#xff0c;僅包括兩個頁面&#xff1a;login.jsp 用來輸入username與password&#xff1b;success.jsp 為登陸成功頁面。error.jsp為登陸失敗頁面。 1、新建web項目“struts2”…

《智能家居》培訓第六天------2019-01-10

目錄&#xff1a; 一&#xff09;攝像頭 二&#xff09;照明 三&#xff09;所想 四&#xff09;總結 一&#xff09;攝像頭 攝像頭這塊學了跟沒學一樣我覺得&#xff0c;攝像頭給的api&#xff0c;yuyv轉rgb24也是給的api&#xff0c;總而言之就是&#xff0c;直接給了兩個源文…

在Linux上按大小列出文件和目錄

This page will show us how to create a list of files and folders ordered by size using standard Linux commands. 該頁面將向我們展示如何使用標準Linux命令創建按大小排序的文件和文件夾列表。 命令 (Command) To get a list with the size of each item in a folder, y…

記一次kafka數據丟失問題的排查

2019獨角獸企業重金招聘Python工程師標準>>> 數據丟失為大事&#xff0c;針對數據丟失的問題我們排查結果如下。 第一&#xff1a;是否存在數據丟失的問題&#xff1f; 存在&#xff0c;且已重現。 第二&#xff1a;是在什么地方丟失的數據&#xff0c;是否是YDB…

Maximum upload size exceede上傳文件大小超出解決

在這里記錄三種方法, 努力提高自己的姿勢水平 application.yml配置spring:servlet:multipart:enabled: truemax-file-size: 10MB #單個文件最大大小max-request-size: 1024MB #上傳數據總大小 application.properties配置spring.servlet.multipart.max-file-size10Mb #單個文件…

ipad iphone開發_如何在iPhone或iPad上更改應用程序的語言

ipad iphone開發BigTunaOnline/Shutterstock.comBigTunaOnline / Shutterstock.comApple’s iOS 13 makes the iPhone and iPad multilingual. Now, you can change the language of an individual app without changing your primary system language. Each app can have its …

Docker最全教程——從理論到實戰(七)

Docker最全教程——從理論到實戰&#xff08;七&#xff09; 原文:Docker最全教程——從理論到實戰&#xff08;七&#xff09;在本系列教程中&#xff0c;筆者希望將必要的知識點圍繞理論、流程&#xff08;工作流程&#xff09;、方法、實踐來進行講解&#xff0c;而不是單純…

Bash Cookbook 學習筆記 【中級】

Read Me 本文是以英文版<bash cookbook> 為基礎整理的筆記&#xff0c;力求脫水2018.01.21 更新完【中級】。內容包括工具、函數、中斷及時間處理等進階主題。本系列其他兩篇&#xff0c;與之互為參考 【基礎】內容涵蓋bash語法等知識點。傳送門【高級】內容涉及腳本安全…

設置Windows 10時如何創建本地帳戶

Windows 10 tries its hardest to make you use a Microsoft account. The option was already hidden, but now it’s not even offered on Windows 10 Home while you’re connected to the internet. Here’s how to create a local account anyway. Windows 10盡最大努力使…

HSQL

Hive的數據存儲  1、Hive中所有的數據都存儲在 HDFS 中&#xff0c;沒有專門的數據存儲格式&#xff08;可支持Text&#xff0c;SequenceFile&#xff0c;ParquetFile&#xff0c;RCFILE等&#xff09;  2、只需要在創建表的時候告訴 Hive 數據中的列分隔符和行分隔符&…

在PowerPoint 2010中將鼠標用作激光筆

Have you ever wished you had a laser pointer to focus attention on a key point in a PowerPoint slideshow? Today, we’ll take a look at how can use use your mouse as a laser pointer in PowerPoint 2010. 您是否曾經希望激光指示器能將注意力集中在PowerPoint幻燈…

Java 8 并發: 原子變量和 ConcurrentMap

原文地址: Java 8 Concurrency Tutorial: Atomic Variables and ConcurrentMap AtomicInteger java.concurrent.atomic 包下有很多原子操作的類。 在有些情況下&#xff0c;原子操作可以在不使用 synchronized 關鍵字和鎖的情況下解決多線程安全問題。 在內部&#xff0c;原子類…

this表示當前對象簡單實例

直接上代碼 class Message { private Channel channel ; // 保存消息發送通道 private String title ; // 消息標題 private String content ; // 消息內容 // 4、調用此構造實例化&#xff0c;此時的channel 主類ch public Message(Channel channel,String title,String cont…

twitter推文不收錄_如何使用Twitter書簽保存推文供以后使用

twitter推文不收錄Khamosh PathakKhamosh PathakTwitter has a new Bookmarks feature that lets you privately save tweets for later. If you’ve been using the Like feature as a workaround for saving tweets, here’s why you should start bookmarking. Twitter具有一…

if的作用域問題 *輸出1~6的隨機數*

1 //測試if語句2 public class TestIf {3 public static void main(String[] args){4 double d Math.random();//0~1之間的小數5 int e (int)(d*5); //[0,4]6 //int f 1(int)(d*6); //[1,6] 擲色子7 System.out.println(e);8 …

為您的Blogger博客設計一個美麗的新主題

Would you like to give your Blogger blog a fresh coat of paint with a new theme? Here’s how you can use the new Template Designer to make your Blogger site stand out from the crowd and look great. 您想給Blogger博客一個新的主題嗎&#xff1f; 您可以通過以…

Lab 6-4

In this lab, we’ll analyze the malware found in the file Lab06-04.exe. Questions and Short Answers What is the difference between the calls made from the main method in Labs 6-3 and 6-4? A: The function at 0x401000 is the check Internet connection method…