Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <algorithm>
- std::vector<std::string> bucketSort(std::vector<std::string> &arr) {
- using namespace std;
- vector<vector<string>> bucket(74);
- vector<string> answer;
- for (auto elem : arr) {
- int index = ((int) elem[0]) - 48;
- bucket[index].push_back(elem);
- }
- for (int i = 0; i < bucket.size(); i++) {
- sort(bucket[i].begin(), bucket[i].end());
- }
- for (int i = 0; i < bucket.size(); i++) {
- if (!bucket[i].empty()) {
- for (int j = 0; j < bucket[i].size(); j++) {
- answer.push_back(bucket[i][j]);
- }
- }
- }
- return answer;
- }
- int main() {
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- int count;
- in >> count;
- vector<string> toSort(count);
- for (int i = 0; i < count; i++){
- in >> toSort[i];
- }
- vector<string> answ = bucketSort(toSort);
- for (auto elem:answ) {
- out << elem << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement