Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. //============================================================================
  2. // Name : Algo6Module2.cpp
  3. // Author :
  4. // Version :
  5. // Copyright : Your copyright notice
  6. // Description : Hello World in C++, Ansi-style
  7. //============================================================================
  8.  
  9. #include <iostream>
  10. #include <cstring>
  11. #include <vector>
  12. #include <cmath>
  13. using namespace std;
  14.  
  15. void sort(vector<string>** main,vector<string>* helper, int size,int deep){
  16.  
  17. }
  18.  
  19.  
  20.  
  21.  
  22. void countSort(vector<string>* data, int n,vector<string>& result,int deep) {
  23. int maxLength = 0;
  24. for( int i = 0; i < n; i++ ) {
  25. int buf = (*data)[i].length();
  26. if (buf > maxLength){
  27. maxLength = buf;
  28. }
  29. }
  30. vector<string>* valuesDataFirst[255];
  31. for (int i=0; i<255;i++){
  32. valuesDataFirst[i] = new vector<string>;
  33. }
  34. //string** valuesDataHelper = new string[256];
  35. for (std::vector<string>::iterator it = (*data).begin() ; it != (*data).end(); ++it){
  36. if ((*it)[deep] != '\0'){
  37. (*(valuesDataFirst[(*it)[deep]])).push_back(*it);
  38. } else {
  39. result.push_back(*it);
  40. }
  41. }
  42. // delete data;
  43. deep += 1;
  44. for (int i=0;i<255;i++){
  45. if(!(*(valuesDataFirst[i])).empty()){
  46. countSort(valuesDataFirst[i],valuesDataFirst[i]->size(),result,deep);
  47. }
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. // else {
  55. // if (deep%2 == 1){
  56. // for (int i = 1; i<255;i++){
  57. // for (std::vector<string>::iterator it = valuesDataFirst[i].begin() ; it != valuesDataFirst[i].end(); ++it){
  58. // if ((*it)[deep] != '\0'){
  59. // valuesDataSecond[(*it)[deep]].push_back(*it);
  60. // } else {
  61. // cout << *it << endl;
  62. // data[counter++]=*it;
  63. // }
  64. // }
  65. // valuesDataFirst[i].clear();
  66. // }
  67. //
  68. // } else {
  69. // for (int i =1; i<255;i++){
  70. // for (std::vector<string>::iterator it = valuesDataSecond[i].begin() ; it != valuesDataSecond[i].end(); ++it){
  71. // if ((*it)[deep] != '\0'){
  72. // valuesDataFirst[(*it)[deep]].push_back(*it);
  73. // } else {
  74. //// cout << *it << endl;
  75. // data[counter++]=*it;
  76. // }
  77. // }
  78. // valuesDataSecond[i].clear();
  79. // }
  80. // }
  81. // }
  82. // flag = false;
  83. // deep++;
  84. // }
  85. }
  86.  
  87.  
  88. int main(){
  89. vector<string> data;
  90. vector <string> result;
  91. string buf = "";
  92. do {
  93. getline(cin, buf);
  94. if (buf.size() > 0) {
  95. // Добавление элемента в конец вектора
  96. data.push_back(buf);
  97. }
  98.  
  99. } while (buf != "");
  100.  
  101. countSort(&data, data.size(),result,0);
  102.  
  103. for( int unsigned i = 0; i < data.size(); i++ ) {
  104. std::cout << result[i] << endl;
  105. }
  106.  
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement