fork(1) download
  1. // -Ofast optimization. Time taken = 2.9s as compared to 4 to 5 seconds in other
  2. // codes.
  3.  
  4. #include <fstream>
  5. #include <string>
  6. #include <vector>
  7. #include <sstream>
  8. #include <cstdio>
  9.  
  10. #include "/Users/me/Applications/fmt/include/fmt/core.h"
  11.  
  12. constexpr std::size_t minfields{33};
  13.  
  14. void splitStr(std::vector<std::string> &splitLine,
  15. std::string_view line,
  16. const char delimiter = ',')
  17. {
  18. // std::string buf;
  19. splitLine.reserve(minfields);
  20. char arr[20] = "";
  21. uint count = 0;
  22. uint j = 0;
  23. for (const char c : line) {
  24. if (c == delimiter) {
  25. if (count == 3 && arr[0] != 'E' && arr[0] != 'T') {
  26. splitLine.clear();
  27. return;
  28. }
  29. arr[j] = '\0';
  30. splitLine.emplace_back(arr);
  31. // buf.clear();
  32. j = 0;
  33. ++count;
  34. }
  35. else {
  36. // buf.append(1, line[i]);
  37. arr[j] = c;
  38. ++j;
  39. }
  40. }
  41.  
  42. }
  43.  
  44. int main(int argc, char *argv[])
  45. {
  46. if (argc < 3) {
  47. exit(EXIT_SUCCESS);
  48. }
  49. std::ifstream inFile(argv[1]);
  50. FILE *outFile = fopen(argv[2], "w");
  51.  
  52. std::string line{};
  53. line.reserve(300);
  54. while (std::getline(inFile, line)) {
  55. std::vector<std::string> split(0);
  56. splitStr(split, line, ';');
  57. if (!split.empty()) {
  58. fmt::print(outFile,
  59. "{},{},{},{},{},{},{},{},{},{},{}\n",
  60. split[0].c_str(),
  61. split[1].c_str(),
  62. split[3].c_str(),
  63. split[4].c_str(),
  64. split[5].c_str(),
  65. split[6].c_str(),
  66. split[10].c_str(),
  67. split[9].c_str(),
  68. split[11].c_str(),
  69. split[7].c_str(),
  70. split[32].c_str());
  71. }
  72. }
  73. }
  74.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty