├── .gitignore ├── runall.sh ├── package.json ├── diff.sh ├── README.md ├── script.js └── template.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /runall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | problem=$1 3 | cd $problem 4 | echo $(pwd) 5 | 6 | g++ -std=c++17 sol.cpp -o solD || { echo "$problem/sol.cpp failed to build. Check for errors."; exit 1; } 7 | echo Compiled successfully... 8 | ls -l solD 9 | 10 | infiles=(`ls in*.txt`) 11 | # echo ${infiles[@]} 12 | for ((i=0; i<${#infiles[@]}; i++)); do 13 | ./solD < in$i.txt > yout$i.txt 14 | done 15 | 16 | cd .. 17 | ./diff.sh $problem 18 | cd .. 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codeforces-contest-bot", 3 | "version": "1.0.0", 4 | "description": "Developed by rachitiitr", 5 | "main": "script.js", 6 | "dependencies": { 7 | "axios": "^0.19.2", 8 | "cheerio": "^1.0.0-rc.3" 9 | }, 10 | "devDependencies": {}, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/rachitiitr/CodeforcesContestBot.git" 17 | }, 18 | "keywords": [ 19 | "competitive-programming", 20 | "javascript", 21 | "bot", 22 | "codeforces-bot", 23 | "rachitiitr" 24 | ], 25 | "author": "Rachit Jain", 26 | "license": "ISC", 27 | "bugs": { 28 | "url": "https://github.com/rachitiitr/CodeforcesContestBot/issues" 29 | }, 30 | "homepage": "https://github.com/rachitiitr/CodeforcesContestBot#readme" 31 | } 32 | -------------------------------------------------------------------------------- /diff.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo Running diff report 4 | cd $1 5 | echo $(pwd) 6 | mainoutfiles=(`ls out*.txt`) 7 | 8 | yourfiles=(`ls yout*.txt`) 9 | 10 | echo ${mainoutfiles[@]} ${yourfiles[@]} 11 | len=${#mainoutfiles[@]} 12 | 13 | # showing only success/fail status per testcase 14 | for((i=0; i<$len; i++)) do 15 | # ToDo: Handle blank lines at end and do file comparison in bash 16 | # cmp -s ${mainoutfiles[i]} ${yourfiles[i]} && echo "Test #$i passed" || echo "Test #$i failed" 17 | echo TestCase $i... 18 | echo =================== 19 | echo Expected Output 20 | cat ${mainoutfiles[i]} && echo 21 | echo Your Output 22 | cat ${yourfiles[i]} && echo 23 | echo =================== 24 | echo 25 | done 26 | 27 | # showing diff via vim 28 | # cmd="vim -c 'set diffopt=filler,vertical' -c 'edit ${mainoutfiles[0]}' -c 'diffsplit ${yourfiles[0]}' " 29 | # for((i=1; i<$len; i++)) do 30 | # cmd="${cmd} -c 'tabe ${mainoutfiles[i]}' -c 'diffsplit ${yourfiles[i]}' " 31 | # done 32 | 33 | # eval $cmd 34 | cd .. 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Live Demo 2 | Watch the YouTube video showing the live demo -> [here](https://www.youtube.com/watch?v=MXYmbJO4bqU) 3 | 4 | # Setup/Installation 5 | ```bash 6 | INSTALLATION_PATH=""; # also the dir where you will write solution 7 | cd $INSTALLATION_PATH 8 | git clone https://github.com/rachitiitr/CodeforcesContestBot.git 9 | cd CodeforcesContestBot 10 | npm install 11 | ``` 12 | 13 | # Usage 14 | ```bash 15 | export CF_CONTEST=https://codeforces.com/contest/1330 16 | node script.js 17 | # will parse all the problems of the contest 18 | # download their testcases 19 | # create multiple directories A B C D E depending on the number of problems in contest 20 | # each directory created will have 21 | # in0.txt out0.txt 22 | # in1.txt out1.txt and so on 23 | # which represent the testcases downloaded 24 | ``` 25 | 26 | # Running sol.cpp on multiple testcases and viewing output 27 | ```bash 28 | ./runall.sh A #if you want to test A/sol.cpp 29 | ./runall.sh D #if you want to test D/sol.cpp against your output vs sample output 30 | # this will run your code on downloaded test cases 31 | # and print to console your output vs expected output 32 | ``` 33 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const cheerio = require('cheerio'); 3 | var fs = require('fs'); 4 | 5 | url = 'http://codeforces.com/contest/1256/problem/C' 6 | 7 | let getTestCaseFromProblemHtml = (dir, html) => { 8 | 9 | fs.copyFileSync(`${dir}/../template.cpp`, `${dir}/sol.cpp`); 10 | data = []; 11 | const $ = cheerio.load(html); 12 | $('div.input pre').each((i, elem) => { 13 | data[i] = { 14 | ...data[i], 15 | input: $(elem).text() 16 | }; 17 | }); 18 | $('div.output pre').each((i, elem) => { 19 | data[i] = ({ 20 | ...data[i], 21 | output: $(elem).text() 22 | }); 23 | }); 24 | console.log(data); 25 | data.forEach((test, i) => { 26 | fs.writeFile(`${dir}/in${i}.txt`, test.input, function(err) { 27 | if(err) { 28 | console.log(err); 29 | } 30 | console.log(`The file ${dir}/in${i}.txt was saved!`); 31 | }); 32 | fs.writeFile(`${dir}/out${i}.txt`, test.output, function(err) { 33 | if(err) { 34 | console.log(err); 35 | } 36 | console.log(`The file ${dir}/out${i}.txt was saved!`); 37 | }); 38 | }) 39 | console.log(data); 40 | } 41 | 42 | function getTestCaseFromProblemUrl(url) { 43 | var dir = `./${url.substring(url.lastIndexOf('/')+1)}`; 44 | 45 | if (!fs.existsSync(dir)){ 46 | fs.mkdirSync(dir); 47 | } 48 | 49 | axios.get(url) 50 | .then(response => { 51 | // console.log(response); 52 | getTestCaseFromProblemHtml(dir, response.data); 53 | } 54 | ) 55 | .catch(err => console.log(err)); 56 | } 57 | 58 | // getTestCaseFromProblemUrl(url); 59 | 60 | contest_url = 'http://codeforces.com/contest/1256'; 61 | 62 | // '' 63 | let getTotalProblemsFromContestHtml = (html) => { 64 | data = []; 65 | const $ = cheerio.load(html); 66 | console.log('parsing'); 67 | $('tr td.id a').each((i, elem) => { 68 | problem_url = 'https://codeforces.com/' + $(elem).attr('href') 69 | console.log(problem_url); 70 | getTestCaseFromProblemUrl(problem_url); 71 | }); 72 | } 73 | 74 | const contestUrl = process.argv[2]; 75 | 76 | axios.get(contestUrl) 77 | .then(response => { 78 | // console.log(response); 79 | getTotalProblemsFromContestHtml(response.data); 80 | }); 81 | -------------------------------------------------------------------------------- /template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define gc getchar_unlocked 4 | #define fo(i,n) for(i=0;in;k