-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
736 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
% CCC 2002 | ||
% problem J1: 0123456789 | ||
% | ||
% print the digits using series of 3 "*"'s | ||
% Gross solution: | ||
% copy paste and create unique print solution for each of 10 digits | ||
|
||
% keybd and screen i/o | ||
|
||
|
||
var n : int | ||
put "Enter a digit between 0 and 9:" | ||
get n | ||
if n = 0 then | ||
put " * * * " | ||
put "* *" | ||
put "* *" | ||
put "* *" | ||
put " " | ||
put "* *" | ||
put "* *" | ||
put "* *" | ||
put " * * * " | ||
elsif n = 1 then | ||
put " " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " " | ||
elsif n = 2 then | ||
put " * * * " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " * * * " | ||
put "* " | ||
put "* " | ||
put "* " | ||
put " * * * " | ||
elsif n = 3 then | ||
put " * * * " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " * * * " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " * * * " | ||
elsif n = 4 then | ||
put " " | ||
put "* *" | ||
put "* *" | ||
put "* *" | ||
put " * * * " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " " | ||
elsif n = 5 then | ||
put " * * * " | ||
put "* " | ||
put "* " | ||
put "* " | ||
put " * * * " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " * * * " | ||
elsif n = 6 then | ||
put " * * * " | ||
put "* " | ||
put "* " | ||
put "* " | ||
put " * * * " | ||
put "* *" | ||
put "* *" | ||
put "* *" | ||
put " * * * " | ||
elsif n = 7 then | ||
put " * * * " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " " | ||
elsif n = 8 then | ||
put " * * * " | ||
put "* *" | ||
put "* *" | ||
put "* *" | ||
put " * * * " | ||
put "* *" | ||
put "* *" | ||
put "* *" | ||
put " * * * " | ||
elsif n = 9 then | ||
put " * * * " | ||
put "* *" | ||
put "* *" | ||
put "* *" | ||
put " * * * " | ||
put " *" | ||
put " *" | ||
put " *" | ||
put " * * * " | ||
end if | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
% CCC 2002 | ||
% problem J2: AmeriCanadian | ||
% | ||
% if a word has > 4 letters and ends with "..kor" | ||
% (k not a vowel: treat "y" as a vowel) | ||
% print the word with "..kour" | ||
|
||
% keybd and screen i/o, repeat until "quit!" entered | ||
|
||
function convert (s : string) : string | ||
if length (s) > 4 then | ||
if s (* - 1.. *) = "or" and | ||
not (s (* - 2) = "a" | ||
or s (* - 2) = "e" | ||
or s (* - 2) = "i" | ||
or s (* - 2) = "o" | ||
or s (* - 2) = "u" | ||
or s (* - 2) = "y") then | ||
result s (1 .. * - 2) + "our" | ||
else | ||
result s | ||
end if | ||
else | ||
result s | ||
end if | ||
end convert | ||
|
||
|
||
var s : string | ||
put "Please enter the words to be translated:" | ||
loop | ||
get s | ||
exit when s = "quit!" | ||
put convert (s) | ||
end loop | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
% CCC 2002 | ||
% Problem S1J3: Student Council's Breakfast | ||
|
||
% given 4 numbers and a total | ||
% print all combinations of those numbers (multiplied by something) | ||
% which give the total | ||
% also print the # of combinations | ||
% print the minimum of the "multiple by" numbers | ||
|
||
% keybd and screen i/o | ||
|
||
var pink, gren, redc, orange, total : int | ||
var tp, tg, tr, tor, mini, count : int | ||
|
||
put "Cost of PINK tickets:" | ||
get pink | ||
put "Cost of GREEN tickets:" | ||
get gren | ||
put "Cost of RED tickets:" | ||
get redc | ||
put "Cost of ORANGE tickets:" | ||
get orange | ||
put "How much must be raised with ticket sales:" | ||
get total | ||
put "combination are" | ||
|
||
mini := 999999 | ||
count := 0 | ||
for a : 0 .. total div pink | ||
tp := a * pink | ||
for b : 0 .. total div gren | ||
tg := b * gren | ||
for c : 0 .. total div redc | ||
tr := c * redc | ||
for d : 0 .. total div orange | ||
tor := d * orange | ||
if tp + tg + tr + tor = total then | ||
if a + b + c + d < mini then | ||
mini := a + b + c + d | ||
end if | ||
count := count + 1 | ||
put "# of PINK is ", a, " # of GREEN is ", b, | ||
" #of RED is ", c, " # of ORANGE is ", d | ||
end if | ||
end for | ||
end for | ||
end for | ||
end for | ||
|
||
put "Total combinations is ", count, "." | ||
put "Minimum number of tickets to print is ", mini, "." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
% CCC 2002 | ||
% Problem S2J4: Fraction Action | ||
|
||
% reduce fraction to lowest terms, | ||
% print as mixed number | ||
% no negatives used | ||
|
||
% keybd and screen i/o | ||
|
||
% recursive version of Euclid's GCD algorithm | ||
function gcd (m, n : int) : int | ||
if n = 0 then | ||
result m | ||
else | ||
result gcd (n, m mod n) | ||
end if | ||
end gcd | ||
|
||
var num, den, hold : int | ||
|
||
put "Numerator" | ||
get num | ||
put "Denominator" | ||
get den | ||
hold := num | ||
num := num div gcd (num, den) | ||
den := den div gcd (hold, den) | ||
if num > den then | ||
put num div den, " " .. | ||
end if | ||
if num mod den > 0 then | ||
put num mod den, "/", den | ||
end if | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// CCC 2002 | ||
// Problem S3J5 Blindfold | ||
|
||
// given a grid with obstacles and a series of moves (R,L,F) | ||
// determine the possible finish points. | ||
|
||
// clear is '.' and obstacle is 'X' | ||
|
||
// brute force method. Take every starting posititon and any of the 4 directions | ||
// and see where you get. If still okay, mark that spot with a '*' | ||
|
||
// file input: r and col of grid given | ||
// then the grid and finally a # and the moves. | ||
// output the grid with the '*' locations. | ||
|
||
import java.awt.*; | ||
import hsa.*; | ||
|
||
public class S3J5Blindfold | ||
{ | ||
static Console cc; | ||
static char [] [] grid; | ||
static int r, c, n; | ||
static char [] m; | ||
|
||
public static void main (String [] args) | ||
{ | ||
cc = new Console (); | ||
|
||
String line; | ||
|
||
TextInputFile fi = new TextInputFile ("blind4.in"); | ||
TextOutputFile fo = new TextOutputFile ("blind4.out"); | ||
|
||
// read grid | ||
r = fi.readInt (); | ||
c = fi.readInt (); | ||
grid = new char [r] [c]; | ||
for (int i = 0 ; i < r ; i++) | ||
{ | ||
line = fi.readLine (); | ||
for (int j = 0 ; j < c ; j++) | ||
grid [i] [j] = line.charAt (j); | ||
} | ||
|
||
//read moves | ||
n = fi.readInt (); | ||
m = new char [n]; | ||
for (int i = 0 ; i < n ; i++) | ||
m [i] = (fi.readLine ()).charAt (0); | ||
|
||
// check each square and direction | ||
for (int i = 0 ; i < r ; i++) | ||
for (int j = 0 ; j < c ; j++) | ||
for (int d = 0 ; d < 360 ; d = d + 90) | ||
check (i, j, d); | ||
|
||
// print grid | ||
for (int i = 0 ; i < r ; i++) | ||
{ | ||
for (int j = 0 ; j < c ; j++) | ||
fo.print (grid [i] [j]); | ||
fo.println (); | ||
} | ||
fi.close (); | ||
fo.close (); | ||
} | ||
|
||
|
||
// this updates the global grid 2D array with a "*" if | ||
// the starting location (i,j) and direction d results in | ||
// a good square. | ||
// quit the process if you go off the square or hit a wall | ||
public static void check (int i, int j, int dir) | ||
{ | ||
int pi, pj, k; | ||
pi = i; | ||
pj = j; | ||
k = 0; | ||
while (pi >= 0 && pi < r && pj >= 0 && pj < c && | ||
(grid [pi] [pj] == '.' || grid [pi] [pj] == '*') && | ||
k < n) | ||
{ | ||
if (m [k] == 'R') | ||
{ | ||
dir = dir - 90; | ||
if (dir < 0) | ||
dir = 270; | ||
} | ||
else if (m [k] == 'L') | ||
dir = (dir + 90) % 360; | ||
else if (m [k] == 'F') | ||
{ | ||
if (dir == 0) | ||
pj = pj + 1; | ||
else if (dir == 180) | ||
pj = pj - 1; | ||
else if (dir == 90) | ||
pi = pi - 1; | ||
else | ||
pi = pi + 1; | ||
} | ||
k++; | ||
} | ||
|
||
if (k >= n && pi >= 0 && pi < r && pj >= 0 && pj < c && | ||
grid [pi] [pj] == '.') | ||
grid [pi] [pj] = '*'; | ||
|
||
} | ||
} | ||
|
Oops, something went wrong.