Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <stdlib.h>
- #include <thread>
- std::vector<std::string> input;
- std::vector<int> numbers;
- void handle_file() {
- std::ifstream file;
- try {
- file.open(input[input.size()-1]);
- }
- catch(std::exception) {
- exit(1);
- }
- input.pop_back();
- while (file.good())
- {
- int num;
- file >> num;
- numbers.push_back(num);
- }
- file.close();
- return;
- }
- int main(int argc, char * argv[]) {
- std::ifstream file;
- file.open(argv[1]);
- while (file.good()) {
- std::string path;
- file >> path;
- input.push_back(path);
- }
- file.close();
- int k = std::atoi(argv[2]);
- for (int i = 0; i < k; ++i) {
- std::thread newThread(handle_file);
- }
- int max = numbers[0];
- for (int i = 0; i < numbers.size(); ++i) {
- if (numbers[i] > max) {
- max = numbers[i];
- }
- }
- std::cout << max << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement