Update CMakeLists.txt
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
size_t get_digits(unsigned long long number) {
|
||||
return static_cast<size_t>(log10(number)) + 1;
|
||||
}
|
||||
|
||||
bool is_number_rising(unsigned long long number) {
|
||||
while (number % 10 == (number / 10) % 10) { number /= 10; }
|
||||
return (number / 10) % 10 < number % 10;
|
||||
}
|
||||
|
||||
struct PartialNumber {
|
||||
unsigned long long number = 0;
|
||||
unsigned long long filled_number = -1;
|
||||
size_t digits = 0;
|
||||
|
||||
void fill() {
|
||||
digits = get_digits(number);
|
||||
filled_number = number;
|
||||
while (filled_number < 10000000000000000) {
|
||||
filled_number *= 10, filled_number += number % 10;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator<(PartialNumber& other) {
|
||||
if (filled_number == -1) { fill(); }
|
||||
if (other.filled_number == -1) { other.fill(); }
|
||||
if (filled_number == other.filled_number) {
|
||||
if (is_number_rising(number)) { return digits < other.digits; }
|
||||
return digits > other.digits;
|
||||
}
|
||||
return filled_number < other.filled_number;
|
||||
}
|
||||
|
||||
bool operator>(PartialNumber& other) {
|
||||
return other < *this;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int nums_amount;
|
||||
cin >> nums_amount;
|
||||
vector<PartialNumber> nums(nums_amount);
|
||||
for (int i = 0; i < nums_amount; i++) {
|
||||
cin >> nums[i].number;
|
||||
}
|
||||
sort(nums.begin(), nums.end());
|
||||
for (int i = nums_amount - 1; i >= 0; i--) {
|
||||
cout << nums[i].number;
|
||||
}
|
||||
cout << " ";
|
||||
for (int i = 0; i < nums_amount; i++) {
|
||||
cout << nums[i].number;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user