'
' University of Evansville High School Programming Contest
' Solution to Practice Problem
'
CLS
PRINT "Hi Bob."
INPUT "How many pennies do you have? ", pennies
INPUT "How many nickels do you have? ", nickels
INPUT "How many dimes do you have? ", dimes
INPUT "How many quarters do you have? ", quarters
PRINT USING "Bob, you have $#####.##."; pennies * .01 + nickels * .05 + dimes * .1 + quarters * .25
'
' University of Evansville High School Programming Contest
' Solution to Problem 1
'
' Quick Formatting Markup Language
'
' April 4, 1998
'
'
DEFINT A-Z
CONST TRUE = 1
CONST FALSE = 0
DIM var$(1 TO 10)
CLS
PRINT "Please enter the text to be formatted: (Enter a blank line to end input.)"
i = 0
DO
i = i + 1
LINE INPUT var$(i)
LOOP WHILE (i <= 10) AND (var$(i) <> "")
linecount = i
boldOn = FALSE
ulineOn = FALSE
FOR i = 1 TO linecount
FOR j = 1 TO LEN(var$(i))
IF MID$(var$(i), j, 1) = "/" THEN
IF j + 1 <= LEN(var$(i)) THEN
j = j + 1
IF MID$(var$(i), j, 1) = "u" THEN
PRINT "_";
IF ulineOn = TRUE THEN
ulineOn = FALSE
ELSE
ulineOn = TRUE
END IF
ELSEIF MID$(var$(i), j, 1) = "b" THEN
IF boldOn = TRUE THEN
boldOn = FALSE
ELSE
boldOn = TRUE
END IF
ELSEIF MID$(var$(i), j, 1) = "t" THEN
IF ulineOn = TRUE THEN
PRINT "____";
ELSE
PRINT " ";
END IF
ELSEIF MID$(var$(i), j, 1) = "n" THEN
ELSEIF MID$(var$(i), j, 1) = "/" THEN
PRINT "/";
ELSE
PRINT MID$(var$(i), j, 1);
END IF ' control character checking
END IF ' last of line checker
ELSE
IF (ulineOn = TRUE) AND (UCASE$(MID$(var$(i), j, 1)) = " ") THEN
PRINT "_";
ELSEIF boldOn = TRUE THEN
PRINT UCASE$(MID$(var$(i), j, 1));
ELSE
PRINT MID$(var$(i), j, 1);
END IF ' if ulineOn or boldOn
END IF ' if is / character
NEXT j
NEXT i
'
' University of Evansville High School Programming Contest
' Solution to Problem 2
'
REM *********TAKE ME OUT TO THE BALLPARK***************
REM ********* Version 1.0 ***************
'
' April 4, 1998
'
'
TYPE Player
Playername AS STRING * 25 'name of player
TeamName AS STRING * 30 'name of the team
Atbats AS INTEGER 'number of at bats
hits AS INTEGER 'number of hits
Ave AS SINGLE
END TYPE
DIM Player(1 TO 20, 1 TO 12) AS Player
DIM PlayerTeam(1 TO 12) AS INTEGER
DIM NumPlayerEntered(1 TO 20) AS INTEGER
DIM NumTeamEntered AS INTEGER
DIM teamaverage(1 TO 20) AS SINGLE
DIM TeamN AS STRING * 25
CLS
PRINT "Welcome to the Wesselman's Summer Softball League!"
PRINT "How many teams are in this year's league";
INPUT NumTeamEntered
FOR y = 1 TO NumTeamEntered
PRINT "Enter the name for team #"; y; " ? ";
LINE INPUT TeamN
PRINT "How many players are on team #"; y;
INPUT NumPlayerEntered(y)
TeamAtBats = 0
TeamHits = 0
FOR x = 1 TO NumPlayerEntered(y)
PRINT "Name for player #"; x; "? ";
LINE INPUT Player(x, y).Playername
PRINT "The number of at bats for player #"; y;
INPUT Player(x, y).Atbats
PRINT "The number of hits for player #"; y;
INPUT Player(x, y).hits
Player(x, y).Ave = Player(x, y).hits / Player(x, y).Atbats
Player(x, y).TeamName = TeamN
TeamAtBats = TeamAtBats + Player(x, y).Atbats
TeamHits = TeamHits + Player(x, y).hits
NEXT x
teamaverage(y) = TeamHits / TeamAtBats
NEXT y
FOR y = 1 TO NumTeamEntered
PRINT Player(1, y).TeamName
FOR x = 1 TO NumPlayerEntered(y)
PRINT "Player "; Player(x, y).Playername,
PRINT USING ".###"; Player(x, y).Ave
NEXT x
PRINT "The team average is ";
PRINT USING ".###"; teamaverage(y);
NEXT y
END
'
' University of Evansville High School Programming Contest
' Solution to Problem 3
'
' Triangulation, Earthquakes, and Llamas
'
' April 4, 1998
'
'
DECLARE FUNCTION IsPointOnCircle% (x#, y#, r#, x1#, y1#)
DEFINT A-Z
CLS
PRINT "University of Evansville - High School Programming Contest"
PRINT "Problem 3 - Solution"
PRINT "Enter the x and y coordinates of the seismograph #1: "
INPUT "(Separate with spaces): ", x1#, y1#
INPUT "Enter the distance from seismograph #1: ", r1#
PRINT "Enter the x and y coordinates of the seismograph #2: "
INPUT "(Separate with spaces): ", x2#, y2#
INPUT "Enter the distance from seismograph #2: ", r2#
PRINT "Enter the x and y coordinates of the seismograph #3: "
INPUT "(Separate with spaces): ", x3#, y3#
INPUT "Enter the distance from seismograph #1: ", r3#
d# = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
IF (d < r1 + r2) THEN
a = (r1 ^ 2 - r2 ^ 2 + d ^ 2) / (2 * d)
h = SQR(r1 ^ 2 - a ^ 2)
x3 = x1 + a * (x2 - x1) / d
y3 = y1 + a * (y2 - y1) / d
x4 = x3 + h * (y2 - y1) / d
y4 = y3 - h * (x2 - x1) / d
x5 = x3 - h * (y2 - y1) / d
y5 = x3 + h * (x2 - x1) / d
END IF
FUNCTION IsPointOnCircle (x#, y#, r#, x1#, y1#)
IsPointOnCircle = ((x1# - x#) ^ 2 + (y1# - y#) ^ 2) = (r# ^ 2)
END FUNCTION
'
' University of Evansville High School Programming Contest
' Solution to Problem 4
'
REM ****** GLOBAL THERMONUCLEAR WARFARE FOR DUMMIES ******
REM ****** Version 1.0 ******
'
' April 4, 1998
'
'
DECLARE FUNCTION alltargetsdead% ()
DECLARE SUB checkdead ()
DECLARE SUB acquirenexttarget ()
DEFINT A-Z
CONST dead = -1
CONST notdead = 0
TYPE Country
cname AS STRING * 15 ' country name
strength AS INTEGER ' strength points remaining
shots AS INTEGER ' how many shots per turn
dead AS INTEGER ' dead flag
curtarget AS INTEGER ' current target index (in firepath())
END TYPE
DIM c(1 TO 5) AS Country
DIM firepath(1 TO 5, 1 TO 4) AS INTEGER
DIM firecountry AS INTEGER
DIM turns AS INTEGER
CLS
' **** ask the obligatory question
PRINT "Do you want to play a game? ";
LINE INPUT a$
IF a$ <> "YES" AND a$ <> "yes" THEN END
' **** load the firing pattern, names, and strength data
' ask for the number of shots
FOR x = 1 TO 5
FOR y = 1 TO 4
' firepath(x,y) contains the y'th target in the list
' of possible targets for country x
READ firepath(x, y)
NEXT y
READ c(x).strength
READ c(x).cname
' initialize values
c(x).shots = 0
c(x).dead = notdead
c(x).curtarget = 1
PRINT c(x).cname; ": enter number of shots per turn";
INPUT c(x).shots
NEXT x
' format -- 1-4 items are target IDs, 5th item is initial strength value
' 6th is the country name (duh.)
DATA 5,2,3,3,100,"United States"
DATA 1,5,4,1,90,"Russia"
DATA 2,1,4,1,110,"China"
DATA 3,5,5,2,50,"England"
DATA 5,4,2,3,70,"France"
turns = 0
DO
turns = turns + 1
' **** cycle through each country in turn to fire
FOR firecountry = 1 TO 5
' **** dead countries can't shoot (duh)
IF c(firecountry).dead = notdead THEN
' **** go through each shot for the country in that turn
FOR shot = 1 TO c(firecountry).shots
IF (alltargetsdead = 0) THEN ' call function to see if all
' targets in firepath()=dead
' **** find next target in firepath() that is not dead
DO
targcountry = firepath(firecountry, c(firecountry).curtarget)
acquirenexttarget ' call function to select next target
LOOP WHILE c(targcountry).dead = dead
' *** BANG! shoot the country and reduce target strength index
targdam = c(targcountry).strength
IF targdam >= 0 THEN targdam = targdam - 1
c(targcountry).strength = targdam
END IF
NEXT shot
END IF
NEXT firecountry
' **** check for those countries that died in this turn (strength <=0)
' and set their dead flag
FOR x = 1 TO 5
IF (c(x).strength < 0) AND (c(x).dead <> dead) THEN
PRINT c(x).cname; " has died in turn"; turns; "!"
c(x).dead = dead
END IF
NEXT x
' call the checkdead function (which handles printing winner/losers, etc.)
checkdead
LOOP
SUB acquirenexttarget
SHARED c() AS Country
SHARED firecountry AS INTEGER
' increment the curtarget index, if it is greater than 4, reset
' curtarget to 1
temp = c(firecountry).curtarget
temp = temp + 1
IF temp = 5 THEN temp = 1
c(firecountry).curtarget = temp
END SUB
FUNCTION alltargetsdead
SHARED firepath() AS INTEGER
SHARED c() AS Country
SHARED firecountry AS INTEGER
alltargetsdead = 1
' function returns 1 if all targets in firepath(firingcountry,x)
' are dead, else returns 0
FOR x = 1 TO 4
IF c(firepath(firecountry, x)).dead = notdead THEN
alltargetsdead = 0
END IF
NEXT x
END FUNCTION
SUB checkdead
SHARED c() AS Country
SHARED turns AS INTEGER
' count the dead
countofdead = 0
FOR x = 1 TO 5
IF c(x).dead = dead THEN countofdead = countofdead + 1
NEXT x
' if all 5 countries are dead, then say so, then terminate program
IF countofdead = 5 THEN
PRINT "ALL PLAYERS ARE DEAD in turn"; turns; "!"
PRINT "Strange game. The only way to win is not to play."
END
END IF
' if only one country survived, print out the "winner" and terminate
IF countofdead = 4 THEN
FOR x = 1 TO 5
IF c(x).dead = notdead THEN
PRINT c(x).cname; " is the winner in turn"; turns; "!"
END
END IF
NEXT x
END IF
' check for allied victory (USA&ENG) (deadlock condition)
IF countofdead = 3 THEN
IF c(1).dead = notdead AND c(4).dead = notdead THEN
PRINT "Allied victory: USA and England win in turn"; turns; "!"
END
END IF
END IF
END SUB
'
' University of Evansville High School Programming Contest
' Solution to Problem 5
'
' The Grand Prize Game
'
' April 4, 1998
'
'
CONST pi = 3.14159
CONST A = -4.9 '9.8 m/s divided by 2
DIM velocity(1 TO 6) AS SINGLE
DIM angle(1 TO 6) AS INTEGER
DIM height AS SINGLE
DIM i AS INTEGER
DIM b AS SINGLE, AdjustedHeight AS SINGLE, airtime AS SINGLE
DIM LowDist AS SINGLE, HighDist AS SINGLE
INPUT height
FOR i = 1 TO 6
INPUT velocity(i), angle(i)
NEXT i
AdjustedHeight = height - .2
FOR i = 1 TO 6
b = velocity(i) * SIN(angle(i) * pi / 180)
airtime = -b - SQR(b * b - 4 * AdjustedHeight * A)
airtime = airtime / (2 * A)
PRINT airtime
Dist = velocity(i) * COS(angle(i) * pi / 180) * airtime
PRINT Dist
LowDist = .6 * i - .3 - .2 'wanted dist - radius of cup
HighDist = .6 * i - .3 + .2 'wanted dist + radius of cup
IF (Dist >= LowDist) AND (Dist <= HighDist) THEN
PRINT "Hit cup "; i
ELSE
PRINT "Missed cup "; i
i = 6
END IF
NEXT i
'
' University of Evansville High School Programming Contest
' Solution to Problem 6
'
REM ***** ROTATE-O-STRING 2000 SOLUTION *****
'
' April 4, 1998
'
'
DIM firstchar AS STRING * 1
DO
PRINT "Please enter your string:"
LINE INPUT userstring$
temp$ = userstring$
IF userstring$ <> "" THEN ' don't execute if there is no string!
DO
PRINT temp$
' store temp$'s first character in firstchar
firstchar = LEFT$(temp$, 1)
' shift the remaining characters in temp$ to the left one
FOR i = 1 TO (LEN(temp$) - 1)
MID$(temp$, i, 1) = MID$(temp$, i + 1, 1)
NEXT i
' copy the (old) first character to the last one in the string
MID$(temp$, LEN(temp$), 1) = firstchar
' loop until the two strings (the original string &
' the rotated string) match
LOOP WHILE (temp$ <> userstring$)
END IF
PRINT temp$
INPUT "Would you like to enter another string"; in$
LOOP WHILE (in$ = "YES" OR in$ = "yes")
PRINT "Thank you for using Rotate-O-String 2000."
Backto the 1998 Problem Set Page
Backto the Programming Contest Home Page