CS 141 - Lab 4
Sequence Divisibility
Directions
Find a partner. Solve the following programming
problem in C++. When you finish, turn it in electronically, one copy
per team. When you are done, you should work on Homework 2 or Programming Assignment 2.
Overview
Given a sequence of n integers and an integer
k, is there a way to add + and - operators to the
sequence so the sum is divisible by k?
Input Spec
(Read until standard input is closed.)
Read integer n, this is how many elements are in the sequence
for this test.
Read integer k, this is what you want the sums to be divisible
by.
Read n integers. This is the sequence for this test.
Output Spec
Your output must match exactly the following, including
whitespace.
For each sequence, print either "Divisible" or "Not divisible"
followed by a newline. Your program should produce no other output.
Testing
Test cases can be found here. Run these using regular UNIX
redirection & testing:
./lab4 < inputFile | diff - outputFile
Where inputFile and outputFile will be one of these or a
pair of your own creation.
lab4test1.in
lab4test1.out
lab4test2.in
lab4test2.out
If the testing line above produces no output when run with
these tests, then you have completed the program.
Recommended Approach
- This is similar to but easier than lab3. You should be able to
finish this in less than 75 lines of code, commented. As always,
figure out the recursion first. Spend the rest of the period working
on other class work