前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ACMSGURU 347 - Join the Strings

ACMSGURU 347 - Join the Strings

作者头像
Reck Zhang
发布2021-08-11 11:01:05
2530
发布2021-08-11 11:01:05
举报
文章被收录于专栏:Reck Zhang

Join the Strings

Problem Description

His Royal Highness King of Berland Berl XV was a very wise man and had a very accomplished wife, who was aware of the fact, that prominent and outstanding personalities once having written down their names on the pages of glorious History, remain there forever. His Royal Highness King Berl XV experienced an intrinsic, lost nowadays, deep and sincere sense of respect and trust for his beloved spouse. So he decided to acquire a chronicler of his own. Due to the ambiguous nature of misunderstanding and the crying injustice of history to ambiguity, he decided to leave all his royal responsibilities aside and made up his royal mind to find the chronicler, who will make him famous, depicting all his heroic deeds truthfully and gloriously enough.

The King assembled the greatest minds of his kingdom at the Academic Chroniclers Meeting (ACM), as he named it, and decided to test their might. The task was to build the Smallest Lexicographical Concatenation (SLC) out of the given N strings. SLC of N strings s1,…, sN is the lexicographically smallest their concatenation si1 +… + siN, where i1,…, iN is a permutation of integers from 1 through N. It’s a great privilege to be a chronicler, so don’t miss your chance and don’t screw it up! Make the king choose you!

Input

The first line of the input file contains a single integer N (1 ≤ N ≤ 100) indicating the number of strings. The following N lines contain N strings, one string per line. The length of each string is no more than 100 characters. Each string consists only of lowercase Latin letters. There are no any leading or trailing spaces.

Output

Print the SLC of the given N strings to the output file as a single line.

Example(s)

sample input

sample output

6itlookslikeaneasyproblem

aneasyitlikelooksproblem

Solution

代码语言:javascript
复制
#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;

    std::vector<std::string> strings(n);
    for(int i = 0; i < n; i++) {
        std::cin >> strings[i];
    }

    std::sort(strings.begin(), strings.end(), [](std::string a, std::string b) {
        return a + b < b + a;
    });

    for(const auto& string : strings) {
        std::cout << string;
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-01-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Join the Strings
    • Problem Description
      • Input
        • Output
          • Example(s)
            • Solution
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档