Created
June 4, 2020 06:22
-
-
Save Ch-sriram/a05ab29757205a509f22a1f28c030d75 to your computer and use it in GitHub Desktop.
Largest Concatenated Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Problem Link: https://practice.geeksforgeeks.org/problems/largest-number-formed-from-an-array/0 | |
| #include <iostream> | |
| #include <algorithm> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| #define ull uint64_t | |
| void largestConcatenatedNumber(vector<string> &nums) { | |
| sort(nums.begin(), nums.end(), | |
| [](string X, string Y){ | |
| string XY = X.append(Y); | |
| string YX = Y.append(X); | |
| return (XY.compare(YX) < 0 ? 0 : 1); | |
| }); | |
| for(ull i = 0; i < nums.size(); ++i) | |
| cout << nums[i]; | |
| cout << endl; | |
| } | |
| int main() { | |
| int t; cin >> t; | |
| while(t--) { | |
| int n; cin >> n; | |
| vector<string> nums(n); | |
| for(int i = 0; i < n; ++i) | |
| cin >> nums[i]; | |
| largestConcatenatedNumber(nums); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment