// -Ofast optimization. Time taken = 2.9s as compared to 4 to 5 seconds in other
// codes.
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <cstdio>
#include "/Users/me/Applications/fmt/include/fmt/core.h"
constexpr std::size_t minfields{33};
void splitStr(std::vector<std::string> &splitLine,
std::string_view line,
const char delimiter = ',')
{
// std::string buf;
splitLine.reserve(minfields);
char arr[20] = "";
uint count = 0;
uint j = 0;
for (const char c : line) {
if (c == delimiter) {
if (count == 3 && arr[0] != 'E' && arr[0] != 'T') {
splitLine.clear();
return;
}
arr[j] = '\0';
splitLine.emplace_back(arr);
// buf.clear();
j = 0;
++count;
}
else {
// buf.append(1, line[i]);
arr[j] = c;
++j;
}
}
}
int main(int argc, char *argv[])
{
if (argc < 3) {
exit(EXIT_SUCCESS);
}
std::ifstream inFile(argv[1]);
FILE *outFile = fopen(argv[2], "w");
std::string line{};
line.reserve(300);
while (std::getline(inFile, line)) {
std::vector<std::string> split(0);
splitStr(split, line, ';');
if (!split.empty()) {
fmt::print(outFile,
"{},{},{},{},{},{},{},{},{},{},{}\n",
split[0].c_str(),
split[1].c_str(),
split[3].c_str(),
split[4].c_str(),
split[5].c_str(),
split[6].c_str(),
split[10].c_str(),
split[9].c_str(),
split[11].c_str(),
split[7].c_str(),
split[32].c_str());
}
}
}
Ly8gLU9mYXN0IG9wdGltaXphdGlvbi4gVGltZSB0YWtlbiA9IDIuOXMgYXMgY29tcGFyZWQgdG8gNCB0byA1IHNlY29uZHMgaW4gb3RoZXIKLy8gY29kZXMuCgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxjc3RkaW8+CgojaW5jbHVkZSAiL1VzZXJzL21lL0FwcGxpY2F0aW9ucy9mbXQvaW5jbHVkZS9mbXQvY29yZS5oIgoKY29uc3RleHByIHN0ZDo6c2l6ZV90IG1pbmZpZWxkc3szM307Cgp2b2lkIHNwbGl0U3RyKHN0ZDo6dmVjdG9yPHN0ZDo6c3RyaW5nPiAmc3BsaXRMaW5lLAogICAgICAgICAgICAgIHN0ZDo6c3RyaW5nX3ZpZXcgbGluZSwKICAgICAgICAgICAgICBjb25zdCBjaGFyIGRlbGltaXRlciA9ICcsJykKewogIC8vICBzdGQ6OnN0cmluZyBidWY7CiAgc3BsaXRMaW5lLnJlc2VydmUobWluZmllbGRzKTsKICBjaGFyIGFyclsyMF0gPSAiIjsKICB1aW50IGNvdW50ID0gMDsKICB1aW50IGogPSAwOwogIGZvciAoY29uc3QgY2hhciBjIDogbGluZSkgewogICAgaWYgKGMgPT0gZGVsaW1pdGVyKSB7CiAgICAgIGlmIChjb3VudCA9PSAzICYmIGFyclswXSAhPSAnRScgJiYgYXJyWzBdICE9ICdUJykgewogICAgICAgIHNwbGl0TGluZS5jbGVhcigpOwogICAgICAgIHJldHVybjsKICAgICAgfQogICAgICBhcnJbal0gPSAnXDAnOwogICAgICBzcGxpdExpbmUuZW1wbGFjZV9iYWNrKGFycik7CiAgICAgIC8vICAgICAgYnVmLmNsZWFyKCk7CiAgICAgIGogPSAwOwogICAgICArK2NvdW50OwogICAgfQogICAgZWxzZSB7CiAgICAgIC8vICAgICAgYnVmLmFwcGVuZCgxLCBsaW5lW2ldKTsKICAgICAgYXJyW2pdID0gYzsKICAgICAgKytqOwogICAgfQogIH0KCn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pCnsKICBpZiAoYXJnYyA8IDMpIHsKICAgIGV4aXQoRVhJVF9TVUNDRVNTKTsKICB9CiAgc3RkOjppZnN0cmVhbSBpbkZpbGUoYXJndlsxXSk7CiAgRklMRSAqb3V0RmlsZSA9IGZvcGVuKGFyZ3ZbMl0sICJ3Iik7CgogIHN0ZDo6c3RyaW5nIGxpbmV7fTsKICBsaW5lLnJlc2VydmUoMzAwKTsKICB3aGlsZSAoc3RkOjpnZXRsaW5lKGluRmlsZSwgbGluZSkpIHsKICAgIHN0ZDo6dmVjdG9yPHN0ZDo6c3RyaW5nPiBzcGxpdCgwKTsKICAgIHNwbGl0U3RyKHNwbGl0LCBsaW5lLCAnOycpOwogICAgaWYgKCFzcGxpdC5lbXB0eSgpKSB7CiAgICAgIGZtdDo6cHJpbnQob3V0RmlsZSwKICAgICAgICAgICAgICAgICAie30se30se30se30se30se30se30se30se30se30se31cbiIsCiAgICAgICAgICAgICAgICAgc3BsaXRbMF0uY19zdHIoKSwKICAgICAgICAgICAgICAgICBzcGxpdFsxXS5jX3N0cigpLAogICAgICAgICAgICAgICAgIHNwbGl0WzNdLmNfc3RyKCksCiAgICAgICAgICAgICAgICAgc3BsaXRbNF0uY19zdHIoKSwKICAgICAgICAgICAgICAgICBzcGxpdFs1XS5jX3N0cigpLAogICAgICAgICAgICAgICAgIHNwbGl0WzZdLmNfc3RyKCksCiAgICAgICAgICAgICAgICAgc3BsaXRbMTBdLmNfc3RyKCksCiAgICAgICAgICAgICAgICAgc3BsaXRbOV0uY19zdHIoKSwKICAgICAgICAgICAgICAgICBzcGxpdFsxMV0uY19zdHIoKSwKICAgICAgICAgICAgICAgICBzcGxpdFs3XS5jX3N0cigpLAogICAgICAgICAgICAgICAgIHNwbGl0WzMyXS5jX3N0cigpKTsKICAgIH0KICB9Cn0K
Main.java:4: error: illegal character: '#'
#include <fstream>
^
Main.java:4: error: class, interface, or enum expected
#include <fstream>
^
Main.java:5: error: illegal character: '#'
#include <string>
^
Main.java:6: error: illegal character: '#'
#include <vector>
^
Main.java:7: error: illegal character: '#'
#include <sstream>
^
Main.java:8: error: illegal character: '#'
#include <cstdio>
^
Main.java:10: error: illegal character: '#'
#include "/Users/me/Applications/fmt/include/fmt/core.h"
^
Main.java:14: error: class, interface, or enum expected
void splitStr(std::vector<std::string> &splitLine,
^
Main.java:20: error: class, interface, or enum expected
char arr[20] = "";
^
Main.java:21: error: class, interface, or enum expected
uint count = 0;
^
Main.java:22: error: class, interface, or enum expected
uint j = 0;
^
Main.java:23: error: class, interface, or enum expected
for (const char c : line) {
^
Main.java:27: error: class, interface, or enum expected
return;
^
Main.java:28: error: class, interface, or enum expected
}
^
Main.java:30: error: class, interface, or enum expected
splitLine.emplace_back(arr);
^
Main.java:32: error: class, interface, or enum expected
j = 0;
^
Main.java:33: error: class, interface, or enum expected
++count;
^
Main.java:34: error: class, interface, or enum expected
}
^
Main.java:38: error: class, interface, or enum expected
++j;
^
Main.java:39: error: class, interface, or enum expected
}
^
Main.java:48: error: class, interface, or enum expected
}
^
Main.java:50: error: class, interface, or enum expected
FILE *outFile = fopen(argv[2], "w");
^
Main.java:52: error: class, interface, or enum expected
std::string line{};
^
Main.java:53: error: class, interface, or enum expected
line.reserve(300);
^
Main.java:54: error: class, interface, or enum expected
while (std::getline(inFile, line)) {
^
Main.java:56: error: class, interface, or enum expected
splitStr(split, line, ';');
^
Main.java:57: error: class, interface, or enum expected
if (!split.empty()) {
^
Main.java:71: error: class, interface, or enum expected
}
^
28 errors