Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
18 changes: 0 additions & 18 deletions .vscode/c_cpp_properties.json

This file was deleted.

13 changes: 0 additions & 13 deletions .vscode/launch.json

This file was deleted.

59 changes: 0 additions & 59 deletions .vscode/settings.json

This file was deleted.

10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,19 @@ Example test files:

Compile the solution:

```
```bash
#Macos
g++ solution.cpp -o solution
#Windows
g++ solution.cpp -o solution.exe
```

Compile the judge:

```
```bash
#Macos
g++ cpjudge.cpp -o cpjudge
#Windows
g++ cpjudge.cpp -o cpjudge
```

Expand Down
53 changes: 30 additions & 23 deletions cpjudge.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

string readFile(string path)
string
readFile (string path)
{
ifstream file(path);
return string((istreambuf_iterator<char>(file)),
istreambuf_iterator<char>());
ifstream file (path);
return string ((istreambuf_iterator<char> (file)),
istreambuf_iterator<char> ());
}

int main()
int
main ()
{
int total = 2;
int passed = 0;
int total = 2;
int passed = 0;

for(int i=1;i<=total;i++)
for (int i = 1; i <= total; i++)
{
string input = "tests/input" + to_string(i) + ".txt";
string expected = "tests/output" + to_string(i) + ".txt";
#ifdef __APPLE__
string input = "tests/input" + to_string (i) + ".txt";
string cmd = "./solution < " + input + " > temp.txt";
#elif _WIN32
string input = ".\\tests\\input" + to_string (i) + ".txt";
string cmd = "cmd /c \"solution.exe < " + input + " > temp.txt\"";

#endif
string expected = "tests/output" + to_string (i) + ".txt";

string cmd = "./solution < " + input + " > temp.txt";
system(cmd.c_str());
system (cmd.c_str ());

string out = readFile("temp.txt");
string exp = readFile(expected);
string out = readFile ("temp.txt");
string exp = readFile (expected);

if(out.find(exp) != string::npos)
if (out.find (exp) != string::npos)
{
cout << "Test " << i << " PASSED\n";
passed++;
cout << "\033[32mTest " << i << " PASSED\033[0m\n";
passed++;
}
else
else
{
cout << "Test " << i << " FAILED\n";
cout << "\033[31mTest " << i << " FAILED\033[0m\n";
}
}

cout << "\nPassed " << passed << "/" << total << " tests\n";
cout << "\nPassed " << passed << "/" << total << " tests\n";
}
Binary file added cpjudgewin.exe
Binary file not shown.
Binary file added solution.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion temp.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-61964191
-1824264137