Advertisement
hacityler

number sorting

Oct 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <fstream>
  3. #include <iostream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. int main(int argc, char *argv[])
  8. {  
  9.     std::ifstream stream(argv[1]);
  10.     std::string line;
  11.    
  12.     std::vector<int> quantity_of_numbers(1000, 0);
  13.    
  14.     int number_count;
  15.  
  16.     while (getline(stream, line))
  17.     {
  18.         int number_to_sort = std::stoi(line);
  19.        
  20.         quantity_of_numbers[number_to_sort]++;
  21.     }
  22.  
  23.     for (int i = 0 ; i < (quantity_of_numbers.capacity()) ; ++i)
  24.     {
  25.         number_count = quantity_of_numbers[i];
  26.  
  27.         for (int j = 0; j < number_count; ++j)
  28.         {
  29.             std::cout << i << std::endl;
  30.         }
  31.     }  
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement