From e0732b73908c3303c670576b3071a087ed8322f1 Mon Sep 17 00:00:00 2001 From: Moulik Adak Date: Tue, 18 Jul 2017 12:22:54 +0530 Subject: [PATCH 1/4] colour coded --- challenges/writers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/challenges/writers.py b/challenges/writers.py index a2dbaa7..a0e8348 100644 --- a/challenges/writers.py +++ b/challenges/writers.py @@ -43,7 +43,10 @@ def write_contests(contests, contest_type): click.secho("%-3s" % str(index+1), nl=False, bold=True) click.secho(" %-50s" % contest_name, nl=False, fg=colors().CONTEST_NAME, bold=True) - click.secho(" %-20s" % time_diff_string, nl=False, fg=colors().TIME_TO_START, bold=True) + if 'start' in contest: + click.secho(" %-20s" % time_diff_string, nl=False, fg=colors().TIME_TO_START, bold=True) + else: + click.secho(" %-20s" % time_diff_string, nl=False, fg=colors().TIME_LEFT, bold=True) click.secho(" %-11s" % str(contest["duration"]), nl=False, bold=True) click.secho(" %-15s" % contest["host_name"], fg=colors().HOST, bold=True) From 6583104dee4e1dd90330a1bb8ab20438d6d6fbf7 Mon Sep 17 00:00:00 2001 From: Moulik Adak Date: Fri, 4 Aug 2017 17:26:16 +0530 Subject: [PATCH 2/4] added codechef cli --- codechef/Template/default.cpp | 36 +++++++ codechef/codechef-cli.py | 188 ++++++++++++++++++++++++++++++++++ 2 files changed, 224 insertions(+) create mode 100644 codechef/Template/default.cpp create mode 100644 codechef/codechef-cli.py diff --git a/codechef/Template/default.cpp b/codechef/Template/default.cpp new file mode 100644 index 0000000..bedc976 --- /dev/null +++ b/codechef/Template/default.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define DEBUG(x) cout << '>' << #x << ':' << x << endl; +#define REP(i,n) for(int i=0;i<(n);i++) +#define FOR(i,a,b) for(int i=(a);i<=(b);i++) +#define FORD(i,a,b) for(int i=(a);i>=(b);i--) +inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; } +const int INF = 1<<29; +typedef long long ll; +inline int two(int n) { return 1 << n; } +inline int test(int n, int b) { return (n>>b)&1; } +inline void set_bit(int & n, int b) { n |= two(b); } +inline void unset_bit(int & n, int b) { n &= ~two(b); } +inline int last_bit(int n) { return n & (-n); } +inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; } +template void chmax(T & a, const T & b) { a = max(a, b); } +template void chmin(T & a, const T & b) { a = min(a, b); } +///////////////////////////////////////////////////////////////////// +int main() +{ + return 0; +} \ No newline at end of file diff --git a/codechef/codechef-cli.py b/codechef/codechef-cli.py new file mode 100644 index 0000000..473fd1f --- /dev/null +++ b/codechef/codechef-cli.py @@ -0,0 +1,188 @@ +from robobrowser import RoboBrowser +from bs4 import BeautifulSoup +import getpass,os,click +from operator import itemgetter +import HTMLParser +h= HTMLParser.HTMLParser() + +login_url = 'http://codechef.com' + + + +def inPre(s): + try: + s = s.split('
')[1].split('
')[0] + except: + s = s.split('')[1].split('')[0] + return s +def getQuesFromList(directory): + browser.open(login_url+directory) + #probs = browser.find_all(class_='problemname') + z=1 + #print type(browser.find_all(class_='problemname', href=True)) + subAccRMS = 0 + probs = browser.find_all(class_='problemrow') + sm = 0 + formattedProbs = [] + + for i in probs: + s=getInner(str(i)) + s.append(float(s[2])*float(s[3])) + formattedProbs.append(s) + + formattedProbs = sorted(formattedProbs, key=itemgetter(4),) + + click.secho("%-5s" % ("#") ,nl=False, bold=True) + click.secho("%-20s" % ("Code") ,nl=False, bold=True) + click.secho("%-55s" % ("Name"), nl=False, bold=True) + click.secho("%-30s" % ("Successful Submissions"), nl=False, bold=True) + click.secho("%-20s" % ("Accuracy"), nl=False ,bold=True) + click.secho("%-20s" % ("Accuracy X Successful Submissions"), fg="white" ,bold=True) + click.echo() + n = len(formattedProbs) + for i in formattedProbs: + name,short,submissions,accuracy,subAcc = i + color = 'red' +# if float(accuracy) * float(submissions) > subAccMedian: +# color = 'yellow' +# if float(accuracy) * float(submissions) > subAccMedian/2: +# color = 'green' + click.secho("%-5s" % (n) ,nl=False, bold=True) + click.secho("%-20s" % (short) ,nl=False, bold=True) + click.secho("%-55s" % (name), nl=False, bold=True) + click.secho("%-30s" % (submissions), nl=False, bold=True) + click.secho("%-20s" % (accuracy), nl=False ,bold=True) + click.secho("%-20s" % (subAcc), fg=color ,bold=True) + n-=1 + return formattedProbs + + +def getQues(ques,tries): + if(tries==2): + return "" + browser.open("https://www.codechef.com/problems/" + ques) + z = browser.find_all(class_="content") + if(len(z)>=3): + return str(browser.parsed)," ".join(getInner(str(z[3]))).replace("<","<").replace(">",">") + else: + return getQues(ques,tries+1) + +def openShell(): + os.system("bash") +def getTemplate(): + f = open('Template/default.cpp','r') + return f.read() + +def getInner(s): + a=[] + x="" + i=0 + flag=0 + while i': + flag-=1 + elif flag==0 and s[i]!="\n": + x+=s[i] + i+=1 + if x!="" and x!="\n": + a.append(x) + return a + +practiceLink = {} + +practiceLink[1] = "/problems/school" +practiceLink[2] = "/problems/easy" +practiceLink[3] = "/problems/medium" +practiceLink[4] = "/problems/hard" + +def getPractice(): + while(1): + print "1. Beginner" + print "2. Easy" + print "3. Medium" + print "4. Hard" + print "5. Shell" + print "99. Back" + option = input() + if option != 99: + qarr = getQuesFromList(practiceLink[int(option)]) + while 1: + print "To select question, enter ques code to view '99' to go back or '#' to go to shell, 'vi filename' to load in vim" + option = raw_input() + if(option=='99'): + break + elif(option=='#'): + os.system('bash') + elif(option.split()[0]=='vi'): + raw,quesStr = getQues(option.split('.')[0].split()[1],0) + os.system("echo \"/*" + quesStr + "*/ \\n" + getTemplate() +"\" > Codes/" + option.split()[1]) + try: + os.system("echo \"" + inPre(raw.split('Input')[1].split('Output')[0]) + "\" > Codes/" + option.split()[1].split('.')[0] + ".in") + os.system("echo \"" + inPre(raw.split('Output')[1].split('Author:')[0]) + "\" > Codes/" + option.split()[1].split('.')[0] + ".out") + except: + pass + os.system('vi Codes/' + option.split()[1]) + elif(option.split()[0]=="run"): + os.system("echo Sample Input : ") + os.system("cat "+option.split()[1]+".in") + os.system("echo Sample Output : ") + os.system("cat "+option.split()[1]+".out") + os.system("g++ -o "+option.split()[1]+" option.split()[1]"+".cpp") + os.system("./"+option.split()[1]) + try: + qu = getQues(option,0) + click.secho(qu,bold=True) + except: + pass + elif(option==2): + pass + elif(option==3): + pass + elif(option==4): + pass + elif(option==5): + openShell() + else: + return + +browser = RoboBrowser(parser="lxml") +browser.open(login_url) + + + +form = browser.get_form(id='new-login-form') + + +#form['name'].value = raw_input("Please enter username : ") #"moulik_nitd" +#form['pass'].value = getpass.getpass("Please enter password : ") #"wWZQebK5Ap" +#browser.submit_form(form) +#Logged in + +user = browser.find(class_='right') + +print " ".join(user.text.split('Account')[0].replace('\n','').split()) + +while 1: + print "1. Practice" + print "2. Contests" + print "3. Shell" + print "4. Show question from question code" + print "99. Logout" + option = input() + if(option==1): + getPractice() + elif(option==2): + getContests() + elif(option==3): + openShell() + elif(option==4): + getQues(raw_input("Input question code")) + else: + exit() + + From e7d5f3058648706478c460a9be3f395af0493352 Mon Sep 17 00:00:00 2001 From: Moulik Adak Date: Fri, 4 Aug 2017 17:34:55 +0530 Subject: [PATCH 3/4] login added --- codechef/Codes/DOMSOL.cpp | 37 +++++++++++++++++++++++++++++++++++++ codechef/codechef-cli.py | 9 +++++---- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 codechef/Codes/DOMSOL.cpp diff --git a/codechef/Codes/DOMSOL.cpp b/codechef/Codes/DOMSOL.cpp new file mode 100644 index 0000000..db1284c --- /dev/null +++ b/codechef/Codes/DOMSOL.cpp @@ -0,0 +1,37 @@ +/*All submissions for this problem are available. In Domino Solitaire, you have a grid with two rows and N columns. Each square in the grid contains an integer A. You are given a supply of rectangular 2 × 1 tiles, each of which exactly covers two adjacent squares of the grid. You have to place tiles to cover all the squares in the grid such that each tile covers two squares and no pair of tiles overlap. The score for a tile is the difference between the bigger and the smaller number that are covered by the tile. The aim of the game is to maximize the sum of the scores of all the tiles.  Here is an example of a grid, along with two different tilings and their scores.The score for Tiling 1 is 12 = (9 − 8) + (6 − 2) + (7 − 1) + (3 − 2) while the score for Tiling 2 is 6 = (8 − 6) + (9 − 7) + (3 − 2) + (2 − 1). There are other tilings possible for this grid, but you can check that Tiling 1 has the maximum score among all tilings. Your task is to read the grid of numbers and compute the maximum score that can be achieved by any tiling of the grid. Your task is to read the grid of numbers and compute the maximum score that can be achieved by any tiling of the grid. Input The first line contains one integer N, the number of columns in the grid. This is followed by 2 lines describing the grid. Each of these lines consists of N integers, separated by blanks.   Output A single integer indicating the maximum score that can be achieved by any tiling of the given grid. Constraints 1 ≤ N ≤ 10 5 1 ≤ A ≤ 10 4   Example Input: 4 8 6 2 3 9 7 1 2 Output: 12 */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define DEBUG(x) cout << '>' << #x << ':' << x << endl; +#define REP(i,n) for(int i=0;i<(n);i++) +#define FOR(i,a,b) for(int i=(a);i<=(b);i++) +#define FORD(i,a,b) for(int i=(a);i>=(b);i--) +inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; } +const int INF = 1<<29; +typedef long long ll; +inline int two(int n) { return 1 << n; } +inline int test(int n, int b) { return (n>>b)&1; } +inline void set_bit(int & n, int b) { n |= two(b); } +inline void unset_bit(int & n, int b) { n &= ~two(b); } +inline int last_bit(int n) { return n & (-n); } +inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; } +template void chmax(T & a, const T & b) { a = max(a, b); } +template void chmin(T & a, const T & b) { a = min(a, b); } +///////////////////////////////////////////////////////////////////// +int main() +{ + return 0; +} diff --git a/codechef/codechef-cli.py b/codechef/codechef-cli.py index 473fd1f..d24f1e3 100644 --- a/codechef/codechef-cli.py +++ b/codechef/codechef-cli.py @@ -157,10 +157,11 @@ def getPractice(): form = browser.get_form(id='new-login-form') - -#form['name'].value = raw_input("Please enter username : ") #"moulik_nitd" -#form['pass'].value = getpass.getpass("Please enter password : ") #"wWZQebK5Ap" -#browser.submit_form(form) +x = raw_input("Login? (y/n)") +if(x=='y'): + form['name'].value = raw_input("Please enter username : ") + form['pass'].value = getpass.getpass("Please enter password : ") + browser.submit_form(form) #Logged in user = browser.find(class_='right') From 6ee0821643517eae4559b4abccf1716979ad4ba9 Mon Sep 17 00:00:00 2001 From: Moulik Adak Date: Fri, 4 Aug 2017 17:46:22 +0530 Subject: [PATCH 4/4] Added getchar_unlocked() based input function in template --- codechef/Template/default.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/codechef/Template/default.cpp b/codechef/Template/default.cpp index bedc976..54f7a4c 100644 --- a/codechef/Template/default.cpp +++ b/codechef/Template/default.cpp @@ -21,6 +21,7 @@ using namespace std; inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; } const int INF = 1<<29; typedef long long ll; +inline void inp(auto &n){n=0; char x; while((x=getchar_unlocked())>='0' && x <= '9') n = 10*n + x - '0'; } inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n>>b)&1; } inline void set_bit(int & n, int b) { n |= two(b); } @@ -32,5 +33,10 @@ template void chmin(T & a, const T & b) { a = min(a, b); } ///////////////////////////////////////////////////////////////////// int main() { + long n=12; + int a=11; + inp(n); + inp(a); + printf("\n%ld\n%d\n",n,a); return 0; -} \ No newline at end of file +}