-
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
13 changed files
with
1,507 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,61 @@ | ||
% CCC 2006 Junior problem 1 | ||
% The New CCC (Canadian Calorie Counting) | ||
% | ||
% simple I/O and if's | ||
|
||
var burger, side, drink, dessert : int | ||
var calorie : int | ||
|
||
put "Welcome to Chip's Fast Food Emporium" | ||
put "Please enter your burger choice: " | ||
get burger | ||
put "Please enter your side order choice: " | ||
get side | ||
put "Please enter your drink choice: " | ||
get drink | ||
put "Please enter your desert choice: " | ||
get dessert | ||
|
||
if burger = 1 then | ||
calorie := 461 | ||
elsif burger = 2 then | ||
calorie := 431 | ||
elsif burger = 3 then | ||
calorie := 420 | ||
else | ||
calorie := 0 | ||
end if | ||
|
||
if side = 1 then | ||
calorie := calorie + 100 | ||
elsif side = 2 then | ||
calorie := calorie + 57 | ||
elsif side = 3 then | ||
calorie := calorie + 70 | ||
else | ||
calorie := calorie + 0 | ||
end if | ||
|
||
if drink = 1 then | ||
calorie := calorie + 130 | ||
elsif drink = 2 then | ||
calorie := calorie + 160 | ||
elsif drink = 3 then | ||
calorie := calorie + 118 | ||
else | ||
calorie := calorie + 0 | ||
end if | ||
|
||
if dessert = 1 then | ||
calorie := calorie + 167 | ||
elsif dessert = 2 then | ||
calorie := calorie + 266 | ||
elsif dessert = 3 then | ||
calorie := calorie + 75 | ||
else | ||
calorie := calorie + 0 | ||
end if | ||
|
||
put "" | ||
put "Your total Calorie count is ", calorie, "." | ||
|
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,30 @@ | ||
% CCC 2006 Junior problem 2 | ||
% Roll the Dice | ||
% | ||
% given to dice with m and n sides, (from 1 to m or n) | ||
% calculate the number of combos which add to 10 | ||
|
||
% a simple loop does the trick | ||
|
||
var n, m : int | ||
var c : int | ||
|
||
put "Enter m: " | ||
get m | ||
put "Enter n: " | ||
get n | ||
|
||
c := 0 | ||
for i : 1 .. m | ||
if 10 - i <= n and 10 - i > 0 then | ||
c := c + 1 | ||
end if | ||
end for | ||
|
||
put "" | ||
if c = 1 then | ||
put "There is ", c, " way to get the sum 10." | ||
else | ||
put "There are ", c, " ways to get the sum 10." | ||
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,48 @@ | ||
% CCC 2006 Junior problem 3 | ||
% Cell-Phone Messaging | ||
% | ||
% determine the time to type a message on a numeric pad | ||
% one sec per keystroke and two sec per pause between | ||
% consecutive letters on the same key. | ||
% | ||
% simple string processing and if's | ||
|
||
var s : string | ||
var t : int | ||
|
||
loop | ||
get s | ||
exit when s = "halt" | ||
t := 0 | ||
for i : 1 .. length (s) | ||
if index("adgjmptw", s (i)) > 0 then | ||
t := t + 1 | ||
elsif index ("behknqux", s (i)) > 0 then | ||
t := t + 2 | ||
elsif index ("cfilorvy", s (i)) > 0 then | ||
t := t + 3 | ||
elsif index ("sz", s (i)) > 0 then | ||
t := t + 4 | ||
end if | ||
if i > 1 and ( (index ("abc", s (i - 1)) > 0 and | ||
index ("abc", s (i)) > 0) or | ||
(index ("def", s (i - 1)) > 0 and | ||
index ("def", s (i)) > 0) or | ||
(index ("ghi", s (i - 1)) > 0 and | ||
index ("ghi", s (i)) > 0) or | ||
(index ("jkl", s (i - 1)) > 0 and | ||
index ("jkl", s (i)) > 0) or | ||
(index ("mno", s (i - 1)) > 0 and | ||
index ("mno", s (i)) > 0) or | ||
(index ("pqrs", s (i - 1)) > 0 and | ||
index ("pqrs", s (i)) > 0) or | ||
(index ("tuv", s (i - 1)) > 0 and | ||
index ("tuv", s (i)) > 0) or | ||
(index ("wxyz", s (i - 1)) > 0 and | ||
index ("wxyz", s (i)) > 0)) then | ||
t := t + 2 | ||
end if | ||
end for | ||
put t | ||
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,105 @@ | ||
% CCC 2006 Junior problem 4 | ||
% Its tough being a teen | ||
% | ||
% given a set of ordered intructions determine the | ||
% order it which to do them. | ||
% | ||
% this involves array processing | ||
% before = the task which must be done first (before) | ||
% after = the task which must be done second (after) | ||
% taken = true/false depending whether ith element has been done | ||
% done = the final order to do the tasks (a string) | ||
|
||
% to determine the order | ||
% cycle thru the numbers 1 to 7 and find first one that can be done. | ||
% if one can be done, add it (get out of loop) and start again at 1 | ||
% (seven times) | ||
% if at any point you get past 7, then the entire thing can't be done. | ||
|
||
|
||
|
||
var before, after : array 1 .. 15 of int | ||
var taken : array 1 .. 15 of boolean | ||
var done : string | ||
var x, y : int | ||
var size : int | ||
var i, k : int | ||
var stop, cantdoit : boolean | ||
|
||
% a task can be done if it is never in "after" | ||
% or all the tasks before it are done. | ||
function canBeDone (i : int) : boolean | ||
var ok : boolean | ||
var neverafter : boolean | ||
var taskbeforedone : boolean | ||
ok := not taken (i) | ||
if ok then | ||
neverafter := true | ||
for j : 1 .. size | ||
if after (j) = i then | ||
neverafter := false | ||
end if | ||
end for | ||
if not neverafter then | ||
taskbeforedone := true | ||
for j : 1 .. size | ||
if after (j) = i and not taken (before (j)) then | ||
taskbeforedone := false | ||
end if | ||
end for | ||
ok := taskbeforedone | ||
end if | ||
end if | ||
result ok | ||
end canBeDone | ||
|
||
|
||
|
||
% get the constraints | ||
before (1) := 1 | ||
after (1) := 7 | ||
before (2) := 1 | ||
after (2) := 4 | ||
before (3) := 2 | ||
after (3) := 1 | ||
before (4) := 3 | ||
after (4) := 4 | ||
before (5) := 3 | ||
after (5) := 5 | ||
size := 5 | ||
loop | ||
get x, y | ||
exit when x = 0 and y = 0 | ||
size := size + 1 | ||
before (size) := x | ||
after (size) := y | ||
end loop | ||
for j : 1 .. 7 | ||
taken (j) := false | ||
end for | ||
done := "" | ||
|
||
% get the order | ||
k := 1 | ||
cantdoit := false | ||
loop | ||
exit when cantdoit or k > 7 | ||
i := 1 | ||
stop := false | ||
loop | ||
exit when i > 7 or stop or cantdoit | ||
if not taken (i) and canBeDone (i) then | ||
taken (i) := true | ||
done := done + intstr (i) + " " | ||
stop := true | ||
end if | ||
i := i + 1 | ||
if i > 7 and not stop then | ||
done := "Cannot complete these tasks. Going to bed." | ||
cantdoit := true | ||
end if | ||
end loop | ||
k := k + 1 | ||
end loop | ||
put done | ||
|
Oops, something went wrong.