Skip to content

Instantly share code, notes, and snippets.

@you74674
Last active December 15, 2017 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save you74674/0675569c88472c95a8f9716ea6421387 to your computer and use it in GitHub Desktop.
Save you74674/0675569c88472c95a8f9716ea6421387 to your computer and use it in GitHub Desktop.
#include<cstdio>
#include<iostream>
#include<fstream>
using namespace std;
string exec(const char* cmd){
string ret;
char buf[128];
FILE *f=popen(cmd, "r");
while(!feof(f))
if(fgets(buf, 128, f) != NULL)
ret += buf;
pclose(f);
return ret;
}
int main(int argc, char** argv)
{
string f1=argv[1];//original
string f2=argv[2];//ncr
string f3=argv[3];//answer
string cmd="diff -Z -B --strip-trailing-cr -q "+f2+" "+f3;
ifstream f1s(f1.c_str()), f2s(f2.c_str());
if(f1s && f2s)
{
string ret=exec(cmd.c_str());
if(ret.length()==0)//ncr is the same as answer
{
cmd="cp "+f3+" "+f1;
exec(cmd.c_str());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment