[Review] NOIP exam topics Luogu P1012

Thinking

ASCII code familiar to soon be able to come up with practice, nothing more than a string concatenation and then sort, as long as the collation work is clear, then sort to make a direct STL just fine. (The title card of a man next to me one afternoon)

Code

#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;
}
Published 40 original articles · won praise 0 · Views 5150

Guess you like

Origin blog.csdn.net/edward00324258/article/details/78387785