/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'bool customCompare(const std::string&, const std::string&)':
foo.cc:21:12: error: a function-definition is not allowed here before '{' token
   21 | int main() {
      |            ^
foo.cc:45:2: error: expected '}' at end of input
   45 | }
      |  ^
foo.cc:7:54: note: to match this '{'
    7 | bool customCompare(const string& a, const string& b) {
      |                                                      ^

Code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool customCompare(const string& a, const string& b) {
   
    if (a.length() != b.length()) {
        return a.length() > b.length();
    }

    for (int i = 0; i < a.length(); i++) {
        if (a[i] != b[i]) {
            return a[i] > b[i];
        }
    }

    return false; 

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N, K;
        cin >> N >> K;

        vector<string> numbers(N);
        for (int i = 0; i < N; i++) {
            cin >> numbers[i];
        }

        sort(numbers.begin(), numbers.end(), customCompare);

        for (int i = 0; i < K; i++) {
            numbers[i] += numbers[i + 1];
            numbers.erase(numbers.begin() + i + 1);
        }

        cout << numbers[0] << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 17:04:17
Judged At
2024-11-11 03:12:56
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes