Skip to content

Added File Comparison and args option for running script. #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.vscode
19 changes: 12 additions & 7 deletions diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yourfiles=(`ls yout*.txt`)

echo ${mainoutfiles[@]} ${yourfiles[@]}
len=${#mainoutfiles[@]}

echo $len
# showing only success/fail status per testcase
for((i=0; i<$len; i++)) do
# ToDo: Handle blank lines at end and do file comparison in bash
Expand All @@ -20,14 +20,19 @@ for((i=0; i<$len; i++)) do
cat ${mainoutfiles[i]} && echo
echo Your Output
cat ${yourfiles[i]} && echo
sed ':a;N;$!ba;s/\r\n/\n/g' ${yourfiles[i]} > check1.txt
sed ':a;N;$!ba;s/\r\n/\n/g' ${mainoutfiles[i]} > check2.txt
RED='\033[0;31m'
NC='\033[0m'
GREEN='\033[0;32m'
cmp -s check1.txt check2.txt && echo -e "${GREEN}Test #$i passed${NC}" || echo -e "${RED}Test #$i failed${NC}"
rm check1.txt check2.txt
echo ===================
echo
done

# showing diff via vim
# cmd="vim -c 'set diffopt=filler,vertical' -c 'edit ${mainoutfiles[0]}' -c 'diffsplit ${yourfiles[0]}' "
# for((i=1; i<$len; i++)) do
# cmd="${cmd} -c 'tabe ${mainoutfiles[i]}' -c 'diffsplit ${yourfiles[i]}' "
done
# cmd="vim -c 'set diffopt=filler,vertical' -c 'edit ${mainoutfiles[0]}' -c 'diffsplit ${yourfiles[0]}' "
# for((i=1; i<$len; i++)) do
# cmd="${cmd} -c 'tabe ${mainoutfiles[i]}' -c 'diffsplit ${yourfiles[i]}' "
# done

# eval $cmd
Expand Down
123 changes: 63 additions & 60 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
const axios = require('axios');
const cheerio = require('cheerio');
var fs = require('fs');

url = 'http://codeforces.com/contest/1256/problem/C'
var args = process.argv.slice(2);
url = 'http://codeforces.com/contest/1256';

let getTestCaseFromProblemHtml = (dir, html) => {

fs.copyFileSync(`${dir}/../template.cpp`, `${dir}/sol.cpp`);
data = [];
const $ = cheerio.load(html);
$('div.input pre').each((i, elem) => {
data[i] = {
...data[i],
input: $(elem).text()
};
});
$('div.output pre').each((i, elem) => {
data[i] = ({
...data[i],
output: $(elem).text()
});
});
console.log(data);
data.forEach((test, i) => {
fs.writeFile(`${dir}/in${i}.txt`, test.input, function(err) {
if(err) {
console.log(err);
}
console.log(`The file ${dir}/in${i}.txt was saved!`);
});
fs.writeFile(`${dir}/out${i}.txt`, test.output, function(err) {
if(err) {
console.log(err);
}
console.log(`The file ${dir}/out${i}.txt was saved!`);
});
})
console.log(data);
}
fs.copyFileSync(`${dir}/../template.cpp`, `${dir}/sol.cpp`);
data = [];
const $ = cheerio.load(html);
$('div.input pre').each((i, elem) => {
data[i] = {
...data[i],
input: $(elem).text(),
};
});
$('div.output pre').each((i, elem) => {
data[i] = {
...data[i],
output: $(elem).text(),
};
});
console.log(data);
data.forEach((test, i) => {
fs.writeFile(`${dir}/in${i}.txt`, test.input, function (err) {
if (err) {
console.log(err);
}
console.log(`The file ${dir}/in${i}.txt was saved!`);
});
fs.writeFile(`${dir}/out${i}.txt`, test.output, function (err) {
if (err) {
console.log(err);
}
console.log(`The file ${dir}/out${i}.txt was saved!`);
});
});
console.log(data);
};

function getTestCaseFromProblemUrl(url) {
var dir = `./${url.substring(url.lastIndexOf('/')+1)}`;
var dir = `./${url.substring(url.lastIndexOf('/') + 1)}`;

if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}

axios.get(url)
.then(response => {
// console.log(response);
getTestCaseFromProblemHtml(dir, response.data);
}
)
.catch(err => console.log(err));
axios
.get(url)
.then((response) => {
// console.log(response);
getTestCaseFromProblemHtml(dir, response.data);
})
.catch((err) => console.log(err));
}

// getTestCaseFromProblemUrl(url);
Expand All @@ -61,18 +60,22 @@ contest_url = 'http://codeforces.com/contest/1256';

// ''
let getTotalProblemsFromContestHtml = (html) => {
data = [];
const $ = cheerio.load(html);
console.log('parsing');
$('tr td.id a').each((i, elem) => {
problem_url = 'https://codeforces.com/' + $(elem).attr('href')
console.log(problem_url);
getTestCaseFromProblemUrl(problem_url);
});
}
data = [];
const $ = cheerio.load(html);
console.log('parsing');
$('tr td.id a').each((i, elem) => {
problem_url = 'https://codeforces.com/' + $(elem).attr('href');
console.log(problem_url);
getTestCaseFromProblemUrl(problem_url);
});
};

axios.get(process.env.CF_CONTEST).then((response) => {
// console.log(response);
getTotalProblemsFromContestHtml(response.data);
});

axios.get(process.env.CF_CONTEST)
.then(response => {
// console.log(response);
getTotalProblemsFromContestHtml(response.data);
});
// axios.get('https://codeforces.com/contest/' + args[0]).then((response) => {
// // console.log(response);
// getTotalProblemsFromContestHtml(response.data);
// });
108 changes: 59 additions & 49 deletions template.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include<bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
Expand All @@ -19,22 +19,23 @@ using namespace std;
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0,lim-1);
return uid(rang);
int rng(int lim)
{
uniform_int_distribution<int> uid(0, lim - 1);
return uid(rang);
}
int mpow(int base, int exp);
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

Expand All @@ -45,49 +46,58 @@ const int N = 3e5, M = N;
vi g[N];
int a[N];

void solve() {
void solve()
{
int i, j, n, m;
}

int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());

int t = 1;
cin >> t;
while(t--) {
solve();
}
int t = 1;
cin >> t;
while (t--)
{
solve();
}

return 0;
return 0;
}

int mpow(int base, int exp) {
int mpow(int base, int exp)
{
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
while (exp > 0)
{
if (exp & 1)
result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}

void ipgraph(int n, int m){
int i, u, v;
while(m--){
cin>>u>>v;
void ipgraph(int n, int m)
{
int i, u, v;
while (m--)
{
cin >> u >> v;
u--, v--;
g[u].pb(v);
g[v].pb(u);
}
g[u].pb(v);
g[v].pb(u);
}
}

void dfs(int u, int par){
for(int v:g[u]){
if (v == par) continue;
dfs(v, u);
}
void dfs(int u, int par)
{
for (int v : g[u])
{
if (v == par)
continue;
dfs(v, u);
}
}