Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- unsigned int SORT_COLOMN;
- bool sort_by_number(std::string *first, std::string *second)
- {
- if (first[SORT_COLOMN].length() == second[SORT_COLOMN].length())
- return first[SORT_COLOMN] < second[SORT_COLOMN];
- else
- return first[SORT_COLOMN].length() < second[SORT_COLOMN].length();
- }
- bool sort_by_text(std::string* first, std::string* second)
- {
- return first[SORT_COLOMN] < second[SORT_COLOMN];
- }
- int main()
- {
- unsigned int n, k, w;
- std::string *name_of_column;
- std::cin >> n >> k >> w;
- for(unsigned int i = 0; i < k; ++i)
- std::cin >> name_of_column[i];
- std::string **data = new std::string*[n];
- for (unsigned int i = 0; i < n; i++)
- * (data + i) = new std::string[k];
- for (unsigned int i = 0; i < n; i++)
- for (unsigned int e = 0; e < k; e++)
- std::cin >> data[i][k];
- while (w--) {
- unsigned int data_amount;
- std::string* data_set = new std::string[data_amount];
- unsigned int* ids = new unsigned int[data_amount];
- for (unsigned int i = 0; i < data_amount; i++)
- {
- for (unsigned int e = 0; e < k; e++)
- {
- if (data_set[i] == name_of_column[e])
- {
- ids[i] = e;
- }
- }
- }
- SORT_COLOMN = ids[0];
- if (data[0][ids[0]][0] >= 30 && data[0][ids[0]][0] <= 57)
- sort(data[0], data[n - 1], sort_by_number);
- else
- sort(data[0], data[n - 1], sort_by_text);
- for (unsigned int i = 0; i < data_amount; ++i)
- std::cout << data_set[i] << ' ';
- std::cout << std::endl;
- for (unsigned int i = 0; i < n; ++i) {
- for (unsigned int e = 0; e < data_amount; e++)
- std::cout << data[i][ids[e]] << ' ';
- std::cout << std::endl;
- }
- delete[] data_set;
- delete[] ids;
- }
- delete[] name_of_column;
- for (unsigned int i = 0; i < n; i++)
- delete[] data[i];
- delete[] data;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement