Programming Problems
Programming Problems
Programming Problems
Background
Carlin is looking for love.
While browsing Reddit one day, he read a very interesting article. The article laid out an algorithm which, given
the name of someone, could calculate a score indicating their compatibility. What's more, a comment from
another Redditor verified the articles claims: “seems legit”.
Carlin could barely contain his excitement, and got to work creating a program that could calculate the
compatibility of a list of individuals, given only the name, and display the results sorted such that the name with
the highest score is at the top, and the lowest score at the bottom. But before he could even fire up his
favourite IDE, he was called away on secret ProgSoc business...
Can you help Carlin find love? Write a program that reads in a list of names from standard input, and outputs a
ranked list of names and scores.
For example, the name 'carlin' breaks down to 0 + 3 + 0 + 0 +3 + 0 = 6. Because the 'a' and the 'I' are vowels
hence contribute 3 each to the score, and none of the other letters contribute to the score.
Then, the number of characters in the name times 0.3 is subtracted from the current score.
Carlin has a score of 6, but has 6 letters in it. So his score of 6 becomes 4.2.
Lastly, the score is rounded down (or in maths terms, floored), and becomes the final score of 4.
When all the lines specified by the first number have been consumed, output must be ordered by rank
descending. Where the rank is the same, the names should be ordered alphabetically ascending. Names
passed in are unique.
Each output line shall be in the form: <name in lower case> :<rank>
Note that there is a SPACE between the name and the colon (:)
Sample Input
6
Jemma
Ray
Maria
Jacinta
Bella
Christen
Sample Output
christen :10
jacinta :9
maria :7
bella :4
jemma :4
ray :2
Notes:
The greatest common divisor, or GCD, of two or more integers is the largest positive integer that divides the
numbers without a remainder. For example, the GCD of 8 and 12 is 4.
Your task is to find, in a list of integers, the two largest numbers that yield the largest GCD.
Data Specification
Input
Multiple lines of input with multiple integers on each line, separated by spaces. Each number shall greater than
1 and less than 1,000,000. There shall be up to 100 numbers on each line. Each line shall be terminated with a
zero (0).
The final line of input shall be marked with a solitary zero (0).
Output
For each line of input, output the two largest numbers that yield the largest GCD, and their GCD.
Sample Input
4 8 24 0
7 11 2 13 23 0
48 64 24 72 0
0
Sample Output
8 24 8
13 23 1
48 72 24
Problem 3: The Great Joy of Harshad Numbers
Problem Description
A Harshad number is an integer that is divisible by the sum of its digits. The name Harshad means “giver of
great joy” in Sanskrit, which makes them an Indian cousin of Happy numbers. Write a program that determines
whether a given integer is a Harshad number or not.
Problem Task
Your output for each number tested is a single line, starting with the number, followed by a space, followed by a
character string signifying the result. If the number is a Harshad number, the result string is “GREAT JOY”. If
not, print “sadness”.
6 6 GREAT JOY
42 42 GREAT JOY
Baron von Enumerate of Transutherland loves to suck blood. He also loves numbers. His favourite numbers
are -- surprise, surprise -- vampire numbers.
A vampire number is a number with an even number of digits (d) that is the product of two numbers that have
d/2 digits taken from the vampire number itself. One of the two numbers can be divisible by 10, but not both.
Unfortunately for the Baron, a love of numbers does not necessarily equate with arithmetic ability. Even with
the aid of a pocket calculator, he is unable to determine which numbers are vampire numbers. Often times, he
gives up his search in frustration and goes out and preys on a few helpless souls.
Luckily, you have a computer and you know how to program it, so you will write a program that takes a list of
numbers and determines the "vampireness" of each number. With it, you will save the Baron from number
rage, and the good citizens of Transutherland from the Baron at the same time!
Data Specification
Input
There will be a series of integers N, (where 1 <= N <= 10,000,000), each on their own line.
Input will be terminated with a line containing a single zero (0). Do not process the zero.
Output
For each number to be tested, write out on its own line:
963
1435
1531
102508
104260
0
Sample Output
No
Yes
No
No
Yes