You are on page 1of 6

Problem 1: Looking For Love

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.

The Compatibility Algorithm


The article states that a compatibility score can be determined based on the characters in the name.

The characters contribute to the score in this arrangement:

 A vowel adds 3 to the score

 A t adds 3 to the score

 A z subtracts 3 from the score

 A p adds 1 to the score

 A k adds 2 to the score

 A s adds 4 to the score

All other characters do not contribute to the score.

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.

In summary, the algorithm:

 Calculates a score based on the characters

 Adjusts it down based on the number of characters in the name

 And rounds it down to an integer number.


One final thing of note, the algorithm is not case sensitive, so the scoring AND the display of names should all
be lowercase.

Input / Output format


The first line your program receives from standard input is a number. This number represents the number of
names N which will follow. Every N lines after that, will be a name. There will be at most 40,000 lines.

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:

 Note the order of the output.

 Names must be converted to lowercase for both display and scoring.

 The sample data will never have a duplicate name.


Problem 2: Greatest Common Divisor
Problem Description

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.

(All calculations are in base 10).

Problem Task

Each line of input is a single number to be tested, N. (1<=N<=9999999)

There may be any number of lines of input.

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”.

Remember, judging of your program's output is case sensitive.


Sample input Sample output

6 6 GREAT JOY

101 101 sadness

42 42 GREAT JOY

999 999 GREAT JOY

1138 1138 sadness


Problem 4: Vampire Numbers
Problem Description

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.

For example: 1435 is a vampire number because 35 x 41 = 1435

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:

 Yes, if the number is a vampire number;


 No, if the number is not a vampire number.
Sample Input

963
1435
1531
102508
104260
0

Sample Output

No
Yes
No
No
Yes

You might also like