Advertisement
Fen1848

Untitled

Jun 9th, 2023
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <stdlib.h>
  6. #include <thread>
  7.  
  8.  
  9. std::vector<std::string> input;
  10. std::vector<int> numbers;
  11.  
  12.  
  13.  
  14.  
  15. void handle_file() {
  16. std::ifstream file;
  17. try {
  18. file.open(input[input.size()-1]);
  19. }
  20. catch(std::exception) {
  21. exit(1);
  22. }
  23. input.pop_back();
  24.  
  25.  
  26. while (file.good())
  27. {
  28. int num;
  29. file >> num;
  30.  
  31.  
  32. numbers.push_back(num);
  33. }
  34. file.close();
  35.  
  36. return;
  37. }
  38.  
  39.  
  40. int main(int argc, char * argv[]) {
  41. std::ifstream file;
  42.  
  43. file.open(argv[1]);
  44.  
  45.  
  46. while (file.good()) {
  47. std::string path;
  48. file >> path;
  49.  
  50.  
  51. input.push_back(path);
  52. }
  53. file.close();
  54.  
  55.  
  56. int k = std::atoi(argv[2]);
  57.  
  58.  
  59. for (int i = 0; i < k; ++i) {
  60. std::thread newThread(handle_file);
  61. }
  62.  
  63.  
  64. int max = numbers[0];
  65. for (int i = 0; i < numbers.size(); ++i) {
  66. if (numbers[i] > max) {
  67. max = numbers[i];
  68. }
  69. }
  70.  
  71.  
  72. std::cout << max << std::endl;
  73.  
  74.  
  75. return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement