Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <vector>
- #include <set>
- #include <string>
- #include <map>
- #include <list>
- #include <algorithm>
- #include <iomanip>
- #include <sstream>
- #include <queue>
- #include <stack>
- #include <deque>
- #include <fstream>
- #include <cmath>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair<ll, ll> pll;
- typedef pair<ld, ld> pld;
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- ll n;
- cin >> n;
- vector<string> a(n);
- for (ll i = 0; i < n; ++i) {
- cin >> ws >> a[i];
- }
- cout << "Initial array:" << endl;
- for (ll i = 0; i < n; ++i) {
- cout << a[i] << (i == n-1?"":", ");
- }
- cout << endl;
- list<string> buckets[10];
- ll m = a[0].length();
- for (ll i = 0; i < m; ++i) {
- cout << "**********" << endl;
- cout << "Phase " << i+1 << endl;
- for (ll j = 0; j < n; ++j) {
- buckets[a[j][m-i-1]-'0'].push_back(a[j]);
- }
- for (ll j = 0; j < 10; ++j) {
- cout << "Bucket " << j << ": ";
- if (buckets[j].empty()) {
- cout << "empty";
- } else {
- auto plast = buckets[j].cend();
- --plast;
- for (auto it = buckets[j].cbegin(); it != buckets[j].cend(); ++it) {
- cout << *it << (it == plast?"":", ");
- }
- }
- cout << endl;
- }
- a.clear();
- for (ll j = 0; j < 10; ++j) {
- for (auto it = buckets[j].cbegin(); it != buckets[j].cend(); ++it) {
- a.push_back(*it);
- }
- buckets[j].clear();
- }
- }
- cout << "**********" << endl;
- cout << "Sorted array:" << endl;
- for (ll i = 0; i < a.size(); ++i) {
- cout << a[i] << (i == a.size()-1?"":", ");
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement