Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <vector>
- using std::cin;
- using std::cout;
- using std::max;
- using std::min;
- using std::string;
- using std::vector;
- using Ll = long long;
- const int k20 = 20;
- const int k10 = 10;
- int len;
- vector<Ll> ar;
- vector<int> less_than;
- vector<Ll> hlp;
- int Digit(Ll num, int par) {
- Ll mod = pow(k10, par + 1);
- Ll div = pow(k10, par);
- return num % mod / div;
- }
- void LSD(int par) {
- less_than.assign(k10, 0);
- for (int id = 0; id < len; ++id) {
- int dig = Digit(ar[id], par);
- less_than[dig]++;
- }
- int cnt = 0;
- for (int id = 0; id < k10; ++id) {
- int point = less_than[id];
- less_than[id] = cnt;
- cnt += point;
- }
- for (int id = 0; id < len; ++id) {
- int dig = Digit(ar[id], par);
- hlp[less_than[dig]] = ar[id];
- less_than[dig]++;
- }
- ar = hlp;
- }
- int main() {
- /*std::ios::sync_with_stdio(false);
- std::cin.tie(0);
- std::cout.tie(0);*/
- cin >> len;
- ar.resize(len);
- hlp.resize(len);
- for (Ll& el : ar) {
- cin >> el;
- }
- for (int par = 0; par < k20; ++par) {
- LSD(par);
- }
- for (Ll el : ar) {
- cout << el << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement