Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<int> v(n);
- for(auto& x : v){
- cin >> x;
- }
- const int Q = 256;
- const int Blocks = 4;
- vector<queue<int>> queues(Q);
- for(int k = 0; k < Blocks; ++k){
- for(int i = 0; i < n; ++i){
- int num = (v[i] >> k*8) & 255;
- queues[num].push(v[i]);
- }
- vector<int> new_v;
- for(auto& q : queues){
- while(!q.empty()) {
- new_v.push_back(q.front());
- q.pop();
- }
- }
- v = new_v;
- }
- for(const auto& x : v){
- cout << x << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment