数串

数串

题目描述

设有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.mzph.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…