66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#include <algorithm>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <fstream>
|
|
#include <errno.h>
|
|
|
|
std::vector<std::string> splitString(const std::string& str) {
|
|
std::istringstream iss(str);
|
|
std::vector<std::string> words;
|
|
std::string word;
|
|
|
|
while (iss >> word) {
|
|
words.push_back(word);
|
|
}
|
|
|
|
return words;
|
|
}
|
|
|
|
int main() {
|
|
std::ifstream inputfile("input");
|
|
std::string input;
|
|
|
|
std::vector<int> l_sl;
|
|
std::vector<int> r_sl;
|
|
if (inputfile.is_open()) {
|
|
// Read each line from the file and store it in the
|
|
// 'line' variable.
|
|
std::string line;
|
|
std::vector<std::string> num_s;
|
|
while (std::getline(inputfile, line)) {
|
|
num_s = splitString(line);
|
|
l_sl.push_back(std::stoi(num_s[0]));
|
|
r_sl.push_back(std::stoi(num_s[1]));
|
|
}
|
|
|
|
// Close the file stream once all lines have been
|
|
// read.
|
|
inputfile.close();
|
|
}
|
|
else {
|
|
// Print an error message to the standard error
|
|
// stream if the file cannot be opened.
|
|
std::cerr << "Unable to open file!" << std::endl;
|
|
return ENOENT;
|
|
}
|
|
std::cout << "right: \n";
|
|
for (int i = 0; i< r_sl.size(); i++) {
|
|
std::cout << i << ": " << r_sl[i] << "\n";
|
|
}
|
|
int min_l;
|
|
int min_r;
|
|
int res = 0;
|
|
for (int i = 0; i < l_sl.size(); i++ ) {
|
|
|
|
|
|
res+= l_sl[i] * std::count(r_sl.begin(), r_sl.end(), l_sl[i]);
|
|
}
|
|
std::cout << "\n\n" << res << "\n\n";
|
|
|
|
|
|
} |