College of the Holy Cross CCSCNE 06 Programming Contest Problems



Similar documents
Third Southern African Regional ACM Collegiate Programming Competition. Sponsored by IBM. Problem Set

Systems I: Computer Organization and Architecture

Number Representation

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Normal Probability Distribution

The string of digits in the binary number system represents the quantity

A LEVEL H446 COMPUTER SCIENCE. Code Challenges (1 20) August 2015

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Programming Languages CIS 443

Playing with Numbers

Introduction to Java. CS 3: Computer Programming in Java

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Practical Programming, 2nd Edition

Useful Number Systems

Informatica e Sistemi in Tempo Reale


Primes. Name Period Number Theory

10 Java API, Exceptions, and Collections

Probability, Statistics, & Data Analysis (PSD) Numbers: Concepts & Properties (NCP)

EdExcel Decision Mathematics 1

1. Define: (a) Variable, (b) Constant, (c) Type, (d) Enumerated Type, (e) Identifier.

9.63 Laboratory in Visual Cognition. Single Factor design. Single design experiment. Experimental design. Textbook Chapters

Pseudo code Tutorial and Exercises Teacher s Version

Arithmetic Coding: Introduction

Addition Methods. Methods Jottings Expanded Compact Examples = 15

Variables, Constants, and Data Types

MACM 101 Discrete Mathematics I

Pemrograman Dasar. Basic Elements Of Java

Chapter 3. Input and output. 3.1 The System class

Positional Numbering System

Java course - IAG0040. Unit testing & Agile Software Development

Arithmetic 1 Progress Ladder

CSI 333 Lecture 1 Number Systems

SQUARE-SQUARE ROOT AND CUBE-CUBE ROOT

2010 Solutions. a + b. a + b 1. (a + b)2 + (b a) 2. (b2 + a 2 ) 2 (a 2 b 2 ) 2

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

NCPC 2013 Presentation of solutions

Probability. Sample space: all the possible outcomes of a probability experiment, i.e., the population of outcomes

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Chapter What is the probability that a card chosen from an ordinary deck of 52 cards is an ace? Ans: 4/52.

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

Numbered Cones for Physical Education Games, Drills, and Exercises For Fun and Fitness

SCIENTIFIC CALCULATOR OPERATION GUIDE. <Write View>

Breaking The Code. Ryan Lowe. Ryan Lowe is currently a Ball State senior with a double major in Computer Science and Mathematics and

Math Workshop October 2010 Fractions and Repeating Decimals

EXAM 2 OVERVIEW. Binay Adhikari

MATHS ACTIVITIES FOR REGISTRATION TIME

The Classes P and NP

Flowchart Techniques

Solution for Homework 2

AMS 5 CHANCE VARIABILITY

Udacity cs101: Building a Search Engine. Extracting a Link

Chapter 2: Elements of Java

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

Chapter 5. Binary, octal and hexadecimal numbers

Regular Languages and Finite State Machines

Assessment For The California Mathematics Standards Grade 6

2009 Chicago Area All-Star Math Team Tryouts Solutions

Example: Find the expected value of the random variable X. X P(X)

Cyber Security Workshop Encryption Reference Manual

ACM International Collegiate Programming Contest 2009

A Programming Language for Mechanical Translation Victor H. Yngve, Massachusetts Institute of Technology, Cambridge, Massachusetts

MEMORY WORK - MATH FACTS 1

CS 106 Introduction to Computer Science I

U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, Notes on Algebra

Speaking and Listening Materials

The programming language C. sws1 1

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

Math 55: Discrete Mathematics

Foundation 2 Games Booklet

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

Romanian Online Dialect Atlas: Crişana

Compiler Construction

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

THEORY of COMPUTATION

Reasoning Strategies for Addition Facts

Chapter 4 & 5 practice set. The actual exam is not multiple choice nor does it contain like questions.

Secrets of printf. 1 Background. 2 Simple Printing. Professor Don Colton. Brigham Young University Hawaii. 2.1 Naturally Special Characters

A Second Course in Mathematics Concepts for Elementary Teachers: Theory, Problems, and Solutions

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

File Specification and Guide to the Returns of Payment Transactions by Payment Settlers (Merchant Acquirers)

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June Dr.-Ing.

THE BINARY NUMBER SYSTEM

Discrete Mathematics

How To Write A Program In Php (Php)

Elementary Statistics and Inference. Elementary Statistics and Inference. 16 The Law of Averages (cont.) 22S:025 or 7P:025.

Welcome to Introduction to programming in Python

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

Possible Stage Two Mathematics Test Topics

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi

The National Numeracy Strategy

The 2010 British Informatics Olympiad

Battleships Searching Algorithms

HOMEWORK # 2 SOLUTIO

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

Micro Motion Modbus Interface Tool Slots and Slot Address Sequences

Transcription:

General Information College of the Holy Cross CCSCNE 06 Programming Contest Problems Your contest account contains sample data files named problemi.dat and problemi.out, i = 1,..., 6, which contain sample input and output data for each problem. These files contents are printed below with the corresponding problem. You must code everything in your chosen language; do not use system utilities in your programs. Your programs will be tested with different input data, so you cannot just print the contents of the sample output file.

Problem 1: Statistics Let x 1,..., x n be numbers. We define their average x and standard deviation σ by x = 1 n (x 1 + + x n ), σ = 1 n ((x 1 x) 2 + + (x n x) 2 ). Your program will read a file named statistics.dat that contains no more than 20 whitespace-separated, double-precision floats on one line. It must print the following to standard output: the number of numbers read, their average, and their standard deviation in the indicated format. For example, if statistics.dat contains 123.45-678.901 0 3.14159-2.71828 5 numbers read, average = -111.006, standard deviation = 287.942 to standard output.

Problem 2: Modulo Arithmetic Just as every child knows the ordinary multiplication table, computer scientists need to know the arithmetic of remainders modulo arithmetic for bases up to 16 (hexadecimal). Your program will read a file named modulo.dat that contains one integer n between 1 and 16 (inclusive) on each line, and may consist of several lines. For each line of the input file, the addition table modulo n to standard output. For example, if modulo.dat contains the single line 5, your program should print + 0 1 2 3 4 0 0 1 2 3 4 1 1 2 3 4 0 2 2 3 4 0 1 3 3 4 0 1 2 4 4 0 1 2 3 In the spirit of the exercise, and to ensure attractive output with 1-character fields, your program should print integers in hexadecimal format: 10 = a, 11 = b, etc.

Problem 3: Bowling A single bowling game consists of ten frames. The object in each frame is to roll a ball at ten bowling pins arranged in an equilateral triangle and to knock down as many pins as possible. For each frame, a bowler is allowed a maximum of two rolls to knock down all ten pins. If the bowler knocks them all down on the first attempt, the frame is scored as a strike. If the bowler does not knock them down on the first attempt in the frame the bowler is allowed a second attempt to knock down the remaining pins. If the bowler succeeds in knocking the rest of the pins down in the second attempt, the frame is scored as a spare. The score for a bowling game consists of sum of the scores for each frame. The score for each frame is the total number of pins knocked down in the frame, plus bonuses for strikes and spares. In particular, if a bowler scores a strike in a particular frame, the score for that frame is ten plus the sum of the next two rolls. If a bowler scores a spare in a particular frame, the score for that frame is ten plus the score of the next roll. If a bowler scores a strike in the tenth (final) frame, the bowler is allowed two more rolls. Similarly, a bowler scoring a spare in the tenth frame is allowed one more roll. The maximum possible score in a game of bowling (strikes in all ten frames plus two extra strikes for the tenth frame strike) is 300. Your program will read an input file named bowling.dat that contains a sequence of bowling game rolls separated by single spaces. The score for a single roll will be represented by one character either a number indicating the number of pins knocked down, a / for a spare or an X for a strike. The input file will contain one game per line. For each line in the input file, the total game score to standard output. The game scores should be left justified and each score should be printed on a separate line. The order of the scores on the output should correspond to the order of the games on the input. For example, if bowling.dat contains 1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2 1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / X 8 0 1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9 your program should print 108 121 120

Problem 4: Palindromes A palindrome is a word, phrase, or sentence that reads the same backwards and forwards, with the possible exception of case, whitespace, and punctuation, such as A man, a plan, a canal...panama!, or Rats live on no evil star. Your program will read an ASCII file named palindromes.dat that contains only alphabetic characters (no digits), whitespace, and punctuation. It must print the longest palindrome in the file to standard output. (Specifically, your program will look for palindromes in the string that results from removing all non-alphabetic characters from the input file.) If the file contains more than one palindrome of maximum length, your program need only print the one that occurs earliest in the file. For example, if palindromes.dat contains A programmer named Otto walks into a lab and asks, Is Java available? Not on these machines, replies the TA, Tom Addams. avaava (from Java available) to standard output, even though maddam (from (Tom Addams) has the same length. It should not print the shorter palindromes otto, noton, etc.

Problem 5: Anagrams Two strings are anagrams (of each other) if they contain the same characters with the same frequencies: stops and psost are anagrams, while stops and stoop are not. (It s not necessary that the permuted strings be English words.) Your program will read an ASCII file named anagrams.dat that contains one string of characters per line. For each line of the file, all anagrams of the string in alphabetical order to standard output, with any repetitions removed. The output from different lines should be separated by a blank line. For example, if anagrams.dat contains abc abaa abc acb bac bca cab cba aaab aaba abaa baaa to standard output. There is no a priori bound on the length of the input strings.

Problem 6: Vitamins Professor Calculus buys multi-vitamin pills in bottles of 100. Being eccentric about his health, he takes only half a pill per day. Upon opening a new bottle ( day zero ), Calculus removes a pill, breaks it in half, and returns one half to the bottle. On each subsequent morning, he removes a pill (or half-pill) at random from the bottle. (That is, the probability of his removing a whole pill is equal to the fraction of pills in the bottle that are whole.) If Calculus removes a whole pill, he breaks it in half, returns one half to the bottle, and takes the other half. If he removes a half-pill, he takes it. On day zero, his bottle contains 100 whole pills, while on the 199th day, the bottle contains exactly one half-pill. While preparing notes for a probability course, Calculus muses about the number of whole pills remaining on day k, and assigns to you his promising student the problem of determining the probability distribution for the number of whole pills on day k, before he extracts the daily dose. Your program will read a file named vitamins.dat that contains one integer per line. When your program reads the integer k, it must print to standard output the line Day k followed by a list of pairs of numbers, one pair per line: The first number w is an integer, a possible number of whole pills remaining in the bottle on the morning of day k; the second is the probability of that many whole pills remaining, represented as a double-precision floating-point number. The pairs must be listed in increasing order of w, and the output for different days must be separated by a blank line. For example, if vitamins.dat contains 0 4 194 Day 0 100 1 Day 4 96 0.941094 97 0.058605 98 0.00030101 Day 194 0 0.374185 1 0.485974 2 0.135321 3 0.00451968 to standard output.