From 9a93cb7ce815a820f00fd273363daddbb7d55be9 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 21 Jul 2020 14:43:05 +0800 Subject: [PATCH] add streamline_csv --- tools/streamline_csv.cpp | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tools/streamline_csv.cpp diff --git a/tools/streamline_csv.cpp b/tools/streamline_csv.cpp new file mode 100644 index 0000000..1fadd68 --- /dev/null +++ b/tools/streamline_csv.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +using namespace std; +ifstream File_input; +ofstream File_output; + +int main() { + string str; + int i, j, num, times; + + // farthest + File_input.open("farthest_raw.csv"); + File_output.open("farthest.csv"); + num = 0; + while (!File_input.eof()) { + File_input >> str; + times = 0; + for (i = 0; i < str.size(); i++) { + if (str[i] == ',') {times++;} + if (times == 3) {break;} + } + File_output << str.substr(0, i) << "\n"; + num++; + if (num % 100000 == 0) {cout << num << "/29334498" << endl;} + File_input.get(); + if (File_input.peek() == '\n') {break;} + } + File_input.close(); + File_output.close(); + + // solution + File_input.open("solution_raw.csv"); + File_output.open("solution.csv"); + num = 0; + while (!File_input.eof()) { + File_input >> str; + times = 0; + for (i = 0; i < str.size(); i++) { + if (str[i] == ',') { + times++; + if (times == 3) {j = i;} + } + if (times == 4) {break;} + } + File_output << str.substr(0, j) << str.substr(i) << "\n"; + num++; + if (num % 100000 == 0) {cout << num << "/29334498" << endl;} + File_input.get(); + if (File_input.peek() == '\n') {break;} + } + File_input.close(); + File_output.close(); + + return 0; +} \ No newline at end of file