Challenging Questions To Do in Java: 1. Palindrome Example 2
Challenging Questions To Do in Java: 1. Palindrome Example 2
01100
01000
00000
Example 2:
Input:
4
0000
0100
0010
0001
19
25
Output:
3
6
7
8
4. SQUARE ENCRYPT
Write a program that encrypts an input string. (For extra marks write a program that
decrypts a given string using the rules outlined above.)
A secret code encrypts a message by putting it in an array and reading down the
columns (blanks are replaced by asterisks and full stops are added to fill up the array).
Imagine a square pattern divided into smaller squares as shown below. As you can
see seven of the smaller squares are filled in. If this is rotated clockwise by 90 degrees
and placed on top of the original pattern then more squares are filled in.
LETS*G
O*TO*T
HE*SAN
DWICH*
SHOP*T
ODAY..
The total number of filled in squares is now 13. Continuing in this way you can again
rotate and add the original pattern to the combination giving 19 black squares and one
more rotation + addition gives 25 black squares.
Example:
Input:
Lets go to the sandwich shop today
Output: Lohdsoe*ewhdtt*ioasoscpy**ah*.gtn*t.
You must write a program that will read in a square pattern and output the original
number of black squares and the number that result from each rotation.
Input:
- an integer N on a single line
- the next N lines consist of the NxN square,
(where 1 represents a black square and 0 represents a white square)
Output:
- four lines containing the number of black squares before each rotation
Example 1 :
Input:
5
10100
Output:
7
13