【NOIP考前题目回顾】Luogu P1012

思路

对ASCII码熟悉的很快就可以想出做法,无非就是字符串拼接然后排序,只要排序规则明了的话排序工作就直接给STL做就好了。(这个题卡了我旁边一哥们一下午)

代码

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>

int nextInt()
{
    int num = 0;
    char c;
    bool flag = false;
    while ((c = std::getchar()) == ' ' || c == '\r' || c == '\t' || c == '\n');
    if (c == '-')
        flag = true;
    else
        num = c - 48;
    while (std::isdigit(c = std::getchar()))
        num = num * 10 + c - 48;
    return (flag ? -1 : 1) * num;
}

std::string a[101];

bool cmp(const std::string s1, const std::string s2)
{
    std::string s3 = s1 + s2;
    std::string s4 = s2 + s1;
    return s3 < s4;
}

int n;

int main(int argc, char **argv)
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n;
    for (int i = 1; i <= n; i++)
        std::cin >> a[i];
    std::sort(a + 1, a + n + 1, cmp);
    for (int i = n; i >= 1; i--)
        std::cout << a[i];
    std::cout << std::endl;
#ifdef __EDWARD_EDIT
    std::cin.get();
    std::cin.get();
#endif
    return 0;
}
发布了40 篇原创文章 · 获赞 0 · 访问量 5150

猜你喜欢

转载自blog.csdn.net/edward00324258/article/details/78387785
今日推荐