Contents
- admissions3.py
- admissions.c
- admissions.cpp
- Admissions.java
- admissions.py
- createPrintableLab.sh
- search_recursive.py
admissions3.py 1/7
[top][prev][next]
"""
Saint Bonaventure University Programming Contest
Problem #1 - Getting Into College
SOLUTION
"""
def main():
criteria = input()
criteriaList = criteria.split()
ap = int(criteriaList[0])
intangibles = int(criteriaList[1])
gpa = int(criteriaList[2])
sat = int(criteriaList[3])
score = ap*2 + intangibles*3 + gpa*0.25 + sat*0.02
if score >= 70:
print("ADMIT")
else:
print("DENY")
main()
admissions.c 2/7
[top][prev][next]
#include<stdio.h>
/*
* Saint Bonaventure University Programming Contest
* Problem #1 - Getting Into College
*
* SOLUTION
*
* To compile: gcc -o admissions admissions.c
*/
int main() {
int ap, intangibles, gpa, sat;
double score;
scanf("%d%d%d%d", &ap, &intangibles, &gpa, &sat);
score = ap*2 + intangibles*3 + gpa*0.25 + sat*0.02;
if (score >= 70) {
printf("ADMIT\n");
}
else {
printf("DENY\n");
}
}
admissions.cpp 3/7
[top][prev][next]
// Saint Bonaventure University Programming Contest
// March 2, 2007
// Problem #1 - Getting Into College
// Team Name: SOLUTION
// To compile: g++ -o admissionscpp admissions.cpp
#include <iostream>
using namespace std;
int main() {
int AP, intangibles, GPA, SAT;
cin >> AP >> intangibles >> GPA >> SAT;
double score = AP*2 + intangibles*3 + GPA*0.25 + SAT*0.02;
if (score >= 70)
cout << "ADMIT" << endl;
else
cout << "DENY" << endl;
return 0;
}
Admissions.java 4/7
[top][prev][next]
import java.util.Scanner;
/**
* Saint Bonaventure University Programming Contest
* Problem #1 - Getting Into College
*
* To compile: javac Admissions.java
*
* @author SOLUTION
* @version March 2, 2007
*/
public class Admissions {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int AP = sc.nextInt();
int intangibles = sc.nextInt();
int GPA = sc.nextInt();
int SAT = sc.nextInt();
double score = AP*2 + intangibles*3 + GPA*0.25 + SAT*0.02;
if (score >= 70) {
System.out.println("ADMIT");
}
else {
System.out.println("DENY");
}
}
}
admissions.py 5/7
[top][prev][next]
"""
Saint Bonaventure University Programming Contest
Problem #1 - Getting Into College
SOLUTION
"""
def main():
criteria = raw_input()
criteriaList = criteria.split()
ap = int(criteriaList[0])
intangibles = int(criteriaList[1])
gpa = int(criteriaList[2])
sat = int(criteriaList[3])
score = ap*2 + intangibles*3 + gpa*0.25 + sat*0.02
if score >= 70:
print "ADMIT"
else:
print "DENY"
main()
createPrintableLab.sh 6/7
[top][prev][next]
# Script to print the students' code neatly
# by Sara Sprenkle, 09.2007
# Updated 01.2017 to just use the name of the assignment.
# Updated 01.2019 to prevent including the old .ps and .out files
# Updated 01.2021 to be able to be run from any directory and
# to create .pdf file and not include .pdf files
ARGS=1 # Number of arguments expected.
E_BADARGS=65 # Exit value if incorrect number of args passed.
test $# -lt $ARGS && echo "Usage: `basename $0` <labdirname>" && exit $E_BADARGS
COURSE=cs111
LABDIR=$1
PATHTOLAB=$HOME/$COURSE/$LABDIR
OUTDIR=$HOME/$COURSE
if [ ! -e $PATHTOLAB ];
then
echo "Directory $PATHTOLAB does not exist"
echo " Check that you're using the correct name."
exit
fi
if [ -f $PATHTOLAB ];
then
echo "ERROR: entered argument ($LABDIR) must be a directory"
exit
fi
base=`basename $LABDIR`
if [ -e $PATHTOLAB/$base.out ] || [ -e $PATHTOLAB/*.ps ] || [ -e $PATHTOLAB/*.pdf ];
then
echo "ERROR: You previously executed this program from"
echo "your assignment directory ($base) instead of the cs111 directory."
echo
echo "Remove $base.out, $base.ps, and $base.pdf from your $base directory and try again."
exit
fi
OUTPUT=$OUTDIR/$base.out
if [ -e $OUTPUT ];
then
rm $OUTPUT
fi
for FILE in `ls $PATHTOLAB/`
do
if [ -f $PATHTOLAB/"$FILE" ];
then
echo "Printing $FILE"
echo -----------------------"$FILE"-------------------- >> $OUTPUT
cat $PATHTOLAB/"$FILE" >> $OUTPUT
fi
done
if [ -e $OUTPUT ];
then
echo "CREATING FILE: $OUTDIR/$base.ps"
enscript -2r -Epython --word-wrap --mark-wrapped-lines=box $OUTDIR/$base.out -o $OUTDIR/$base.ps
echo "CREATING PDF: $OUTDIR/$base.pdf"
ps2pdf $OUTDIR/$base.ps $OUTDIR/$base.pdf
else
echo "ERROR: $OUTDIR/$base.out does not exist; could not create ps file"
fi
./search_recursive.py 3/3
[top][prev][next]
# Recursive Binary Search Implementation
# By Sara Sprenkle
# represents that binarySearch did not find the key
NOT_FOUND=-1
def main():
integers = range(1,20,2)
print("The list to search: ", integers)
print()
findMeList = [1, 4, 15, 16, 17]
for key in findMeList:
print("Search for", key)
# binarySearch returns the position the number was found, or -1 if it was
# not found. Translate the result from binarySearch to a True or False
pos = recBinarySearch(integers, key)
binFound = pos != NOT_FOUND
print("Binary: Found?", binFound)
print()
print("Repeast search, using a different recursive implementation")
for key in findMeList:
print("Search for", key)
# binarySearch returns the position the number was found, or -1 if it was
# not found. Translate the result from binarySearch to a True or False
pos = recBinarySearchWithIndices(integers, key, 0, len(integers))
binFound = pos != NOT_FOUND
print("Binary: Found?", binFound)
print()
def recBinarySearch(searchlist, key):
"""Literally divide the list in half. Issues: creates multiple lists.
Each call to the function requires another list (of ~half the size of
the original)."""
# Base case: ran out of elements in the list
if len(searchlist) == 0:
return NOT_FOUND
mid = len(searchlist)//2
valueAtMid = searchlist[mid]
if valueAtMid == key:
return mid
if searchlist[mid] < key: # search upper half
return recBinarySearch(searchlist[mid+1:], key)
else: # search lower half
return recBinarySearch(searchlist[:mid], key)
def recBinarySearchWithIndices(searchlist, key, low, high):
"""Recursive search using the indices to
cut the search space in half each time.
"""
# Base case: ran out of elements in the list
if low > high:
return NOT_FOUND
mid = (low+high)//2
valueAtMid = searchlist[mid]
if valueAtMid == key:
return mid
if searchlist[mid] < key: # search upper half
return recBinarySearchWithIndices(searchlist, key, mid+1, high)
else: # search lower half
return recBinarySearchWithIndices(searchlist, key, low, mid-1)
main()
Generated by GNU Enscript 1.6.6.