## ruchitraj93

BAN USER- 0of 0 votes

AnswerCaeser;s Cipher is a very famous encryptiontechnique used in crptography.It is a type of substitution cipher in which each letter in the plaintext is replaced by letter some fixed number of positions down the alphabet.For example,with a shift of 3 ,D would be replaced bt G,E would become H,X would become A and so on.

- ruchitraj93 in India

Encryption of a letter x by a shift k can bedescribed mathematically as Ek(X)=(X+K)%26.

Given a plain text and it's corresponding ciphertext,output the minimum no negative value of shift that was used to encrypt the plaintext or else output -1 if it is no possible to obtain the given ciphertext from the given plaintext using caeser's cipher technique.

Input

The first line of the input contains Q,denoting the number of queries.

The next Q lines contain two strings s and t consisting of only uppercase letters

output::

For each test case,output a single non negative integer denoting the minimum value of shift that was used to encrypt the the plaintext or else print -1 if the answer does not exist.

Sample Input OUTPUT

2 3

ABC -1

DEF

AAA

PQR| Report Duplicate | Flag | PURGE

Persistent Systems SDE1 - 0of 0 votes

AnswersWrite a Code

- ruchitraj93 in India

Steve is going to throw a party at his place tonight.He needs to visit two shops near his home-the first shop is d1 meters away from his place,the second shop is d2 meters away from his place, and there are d3 meters between these two shops.Calculate the minimum distance he needs to walk to visit both both shops and return back home. Steve always start from his palce.He can only travel using these 3 routes.HE can use any route any amount of time necessary,the only thing he needs to achieve is the minimum distance.

Find the minimum distance Steve has to walk to visit both shops and return home.

input: 1,1,1

output: 4

input: 10,20,30

output: 60| Report Duplicate | Flag | PURGE

Practo Software Developer Java

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

3 and -1 are outputs

- ruchitraj93 March 03, 2017