Advertisement
achulkov2

Untitled

Mar 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <vector>
  5. #include <set>
  6. #include <string>
  7. #include <map>
  8. #include <list>
  9. #include <algorithm>
  10. #include <iomanip>
  11. #include <sstream>
  12. #include <queue>
  13. #include <stack>
  14. #include <deque>
  15. #include <fstream>
  16. #include <cmath>
  17.  
  18. using namespace std;
  19.  
  20. typedef long long ll;
  21. typedef long double ld;
  22.  
  23. typedef pair<ll, ll> pll;
  24. typedef pair<ld, ld> pld;
  25.  
  26. int main() {
  27. freopen("input.txt", "r", stdin);
  28. freopen("output.txt", "w", stdout);
  29.  
  30. ll n;
  31. cin >> n;
  32. vector<string> a(n);
  33. for (ll i = 0; i < n; ++i) {
  34. cin >> ws >> a[i];
  35. }
  36.  
  37. cout << "Initial array:" << endl;
  38. for (ll i = 0; i < n; ++i) {
  39. cout << a[i] << (i == n-1?"":", ");
  40. }
  41. cout << endl;
  42.  
  43. list<string> buckets[10];
  44. ll m = a[0].length();
  45. for (ll i = 0; i < m; ++i) {
  46. cout << "**********" << endl;
  47. cout << "Phase " << i+1 << endl;
  48. for (ll j = 0; j < n; ++j) {
  49. buckets[a[j][m-i-1]-'0'].push_back(a[j]);
  50. }
  51. for (ll j = 0; j < 10; ++j) {
  52. cout << "Bucket " << j << ": ";
  53. if (buckets[j].empty()) {
  54. cout << "empty";
  55. } else {
  56. auto plast = buckets[j].cend();
  57. --plast;
  58. for (auto it = buckets[j].cbegin(); it != buckets[j].cend(); ++it) {
  59. cout << *it << (it == plast?"":", ");
  60. }
  61. }
  62. cout << endl;
  63. }
  64. a.clear();
  65. for (ll j = 0; j < 10; ++j) {
  66. for (auto it = buckets[j].cbegin(); it != buckets[j].cend(); ++it) {
  67. a.push_back(*it);
  68. }
  69. buckets[j].clear();
  70. }
  71. }
  72. cout << "**********" << endl;
  73. cout << "Sorted array:" << endl;
  74. for (ll i = 0; i < a.size(); ++i) {
  75. cout << a[i] << (i == a.size()-1?"":", ");
  76. }
  77. cout << endl;
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement