Skip to content

Commit f4d5973

Browse files
committed
Blogs for the practice contests
1 parent 66e8ed8 commit f4d5973

19 files changed

+263
-3
lines changed

_posts/2018-10-05-comp-numb-sys.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ are converting from base 10 to base n, and vice-versa. Both are described
3636
in further detail in the problem set.
3737

3838
For practice, try solving the problems linked
39-
[here.]({{ site.url }}/cpt-blog/misc_files/comp-number-systems.pdf)
39+
[here.]({{ site.url }}/cpt-blog/tutorials/comp-number-systems.pdf)
4040
Think about the process rather than applying memorized techniques:
4141
jot down any information you see or patterns you observe, and view
4242
exploring the problem in any manner as progress.

_posts/2018-10-19-recursion.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ categories: comp1
88

99
I'm still in the process of writing solutions for the recursion
1010
problems. Consequently, I've attached the two TJ ICT problem sets
11-
[here]({{ site.url }}/cpt-blog/misc_files/Recursion.pdf) and
12-
[here.]({{ site.url }}/cpt-blog/misc_files/Recursion_Problems.pdf)
11+
[here]({{ site.url }}/cpt-blog/tutorials/Recursion.pdf) and
12+
[here.]({{ site.url }}/cpt-blog/tutorials/Recursion_Problems.pdf)
1313

1414
Stay tuned for the solutions and official write-ups of training material.
1515
As for now, we'll just go over this stuff verbally in our training.

_posts/2018-11-09-c1-p1.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
layout: post
3+
title: Practice Contest #1 for Contest #1
4+
date: 2018-11-09 05:42:29
5+
author: Sanjit Bhat
6+
categories: info
7+
---
8+
9+
Short Answers: [here]({{ site.url }}/cpt-blog/contests/16-17-c1.pdf)
10+
11+
Short Answer Solutions: [here]({{ site.url }}/cpt-blog/contests/16-17-c1-sol.pdf)
12+
13+
Coding Problem: [here]({{ site.url }}/cpt-blog/contests/16-17-c1-agram.pdf)
14+
15+
Test Data: [here]({{ site.url }}/cpt-blog/contests/16-17-c1-agram.in)
16+
17+
Correct Outputs: [here]({{ site.url }}/cpt-blog/contests/16-17-c1-agram_correct.out)
18+
19+
Sanjit's Solution: [here]({{ site.url }}/cpt-blog/contests/16-17-c1-agram_sanjit_bhat.pdf)

_posts/2018-11-30-c1-p2.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
layout: post
3+
title: Practice Contest #2 for Contest #1
4+
date: 2018-11-30 05:42:29
5+
author: Sanjit Bhat
6+
categories: info
7+
---
8+
9+
Short Answers: [here]({{ site.url }}/cpt-blog/contests/17-18-c1.pdf)
10+
11+
Short Answer Solutions: [here]({{ site.url }}/cpt-blog/contests/17-18-c1-sol.pdf)
12+
13+
Coding Problem: [here]({{ site.url }}/cpt-blog/contests/17-18-c1-ninetynine.pdf)
14+
15+
Test Data: [here]({{ site.url }}/cpt-blog/contests/17-18-c1-ninetynine.in)
16+
17+
Correct Outputs: [here]({{ site.url }}/cpt-blog/contests/17-18-c1-ninetynine_correct.out)
18+
19+
Sanjit's Solution: [here]({{ site.url }}/cpt-blog/contests/17-18-c1-ninetynine_sanjit_bhat.pdf)

contests/16-17-c1-agram.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2H, 3S, 4D, AH, 9H, AC
2+
7D, 3D, 8H, 5S, KC, AD
3+
TS, AH, AC, AD, JC, QH
4+
8C, 3D, 4H, 9S, TD, QS
5+
AS, KD, TC, 5H, 5D, 6C

contests/16-17-c1-agram.pdf

85.1 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
9H
2+
AD
3+
AC
4+
3D
5+
5D
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Sanjit Bhat
3+
ACSL agram
4+
Contest #1 2016-17
5+
Acton Boxborough Regional High School
6+
Senior Division
7+
*/
8+
9+
import java.io.*;
10+
import java.util.*;
11+
12+
public class agram_sanjit_bhat {
13+
static String your_name = "Sanjit Bhat";
14+
static String prob_name = "agram"; // this needs to be standardized across everyone's code
15+
// file names should be "{prob_name}_{first name}_{last name}.java". This is for file-keeping sake as we can't have two files with the same name.
16+
17+
public static void main(String[] args) throws IOException {
18+
Scanner sc = new Scanner(new File(prob_name + ".in"));
19+
PrintWriter out = new PrintWriter(new FileWriter(prob_name + ".out"), true); // no buffering in case program craps out. Prev test cases will be outputted
20+
out.println(your_name); // MUST include this
21+
22+
for (int l = 0; l < 5; l++) {
23+
try { // use try catch in case code craps out on one test case
24+
String input = sc.nextLine();
25+
String[] cards = input.split(", ");
26+
27+
char[] suits = {'S', 'H', 'D', 'C'};
28+
HashMap<Character, Integer> suit_vals = new HashMap<>();
29+
for (int i = 0; i < suits.length; i++) {
30+
suit_vals.put(suits[i], i);
31+
}
32+
33+
char[] ranks = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
34+
HashMap<Character, Integer> rank_vals = new HashMap<>();
35+
for (int i = 0; i < ranks.length; i++) {
36+
rank_vals.put(ranks[i], i);
37+
}
38+
39+
char opp_rank = cards[0].charAt(0);
40+
char opp_suit = cards[0].charAt(1);
41+
int opp_rank_val = rank_vals.get(opp_rank);
42+
43+
char higher_in_suit = 'N'; // lowest card in same suit that's higher than opponent card
44+
char lowest_in_suit = 'N'; // lowest card in same suit
45+
char lowest_overall_rank = 'N'; // rank of lowest card overall
46+
char lowest_overall_suit = 'N'; // suit of lowest card overall
47+
48+
for (int i = 1; i < cards.length; i++) {
49+
char curr_rank = cards[i].charAt(0);
50+
char curr_suit = cards[i].charAt(1);
51+
int curr_rank_val = rank_vals.get(curr_rank);
52+
if (curr_suit == opp_suit && curr_rank_val > opp_rank_val &&
53+
(higher_in_suit == 'N' || curr_rank_val < rank_vals.get(higher_in_suit))) {
54+
higher_in_suit = curr_rank;
55+
}
56+
if (curr_suit == opp_suit && (lowest_in_suit == 'N' || curr_rank_val < rank_vals.get(lowest_in_suit))) {
57+
lowest_in_suit = curr_rank;
58+
}
59+
if (lowest_overall_rank == 'N' || curr_rank_val < rank_vals.get(lowest_overall_rank) ||
60+
(curr_rank_val == rank_vals.get(lowest_overall_rank) &&
61+
suit_vals.get(curr_suit) > suit_vals.get(lowest_overall_suit))) {
62+
lowest_overall_rank = curr_rank;
63+
lowest_overall_suit = curr_suit;
64+
}
65+
}
66+
67+
if (higher_in_suit != 'N') {
68+
out.println("" + higher_in_suit + opp_suit); // remember to print to .out file for all test cases
69+
} else if (lowest_in_suit != 'N') {
70+
out.println("" + lowest_in_suit + opp_suit);
71+
} else {
72+
out.println("" + lowest_overall_rank + lowest_overall_suit);
73+
}
74+
} catch (Exception e) {
75+
out.println("Something went wrong with this test case"); // even if code craps out on one test case, your code will move on and grader will be fine
76+
e.printStackTrace();
77+
}
78+
}
79+
out.close();
80+
}
81+
}

contests/16-17-c1-sol.pdf

98.5 KB
Binary file not shown.

contests/16-17-c1.pdf

108 KB
Binary file not shown.

0 commit comments

Comments
 (0)