Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Rotate Words Longer than given Length L by K lette

Given a sentence, write a program to rotate words longer than given length L by K letters towards the right.

Note: Even if K is greater than word length, rotate the word multiple times so that K letters will be rotated towards right.Input


The first line of input will contain a string.

The second line of input will contain two space-separated integers, denoting L and K.Output


The output should be a single line containing the sentence by rotating the words whose length is greater than L by K letters towards right.

Sample Input 1

My parents and I went to a movie

2 1

Sample Output 1

My sparent dan I twen to a emovi

Sample Input 2

We drink coffee every morning

4 30

Sample Output 2

We drink coffee every ngmorni


Given a MxN matrix, write a program to replace all elements that do not belong to principal-diagonal & anti-diagonal with Zeros.

Principal-diagonal elements are the set of elements of a matrix that lie on the line joining the top left corner to the bottom right corner.

Anti-diagonal elements are the set of elements of a matrix that lie on the line joining the bottom left corner to the top right corner.Input


The first line of input will contain two space-separated integers, denoting MxN matrix.

The next M lines will contain N space-separated integers.Output


The output should be MxN matrix by replacing elements that do not belong to principal-diagonal and anti-diagonal with Zeros. Print each row as a space separated integers in a single line.

Sample Input 1

5 5

4 3 7 6 4

4 4 7 7 6

9 5 8 5 9

3 6 6 2 4

3 7 4 4 3

Sample Output 1

4 0 0 0 4

0 4 0 7 0

0 0 8 0 0

0 6 0 2 0

3 0 0 0 3


Given a sentence, write a program to mix the words based on their index locations. The first word in the output should contain the first letter of each word in the given sentence and the second word should contain the second letter of each word in the given sentence and so on.


Note: The nth word in the output should contain nth letter of each word in the given sentence. The letters of the output word should be in same order as the words in the given sentence. If a word in the given sentence doesn't have n-letters, you can skip it while considering the letters of the n-th word.Input


The input will be a single line containing a string.Output


The output should be a single line containing the words by mixing based on their index locations.

Sample Input 1

Welcome to your first problem

Sample Output 1

Wtyfp eooir luro crsb otl me em


Given a list of integers, write a program to print the count of all possible unique combinations of numbers whose sum is equal to K.

Input


The first line of input will contain space-separated integers.

The second line of input will contain an integer, denoting K.Output


The output should be containing the count of all unique combinations of numbers whose sum is equal to K.

Sample Input 1

2 4 6 1 3

6

Sample Output 1

3


Rotate Matrix Rings

Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.


Input


The first line of input will be two space-separated integers, denoting the M and N.

The next M lines will contain N space-separated integers.

The next line will contain an integer, denoting K.


Output


The output should be M*N matrix by rotating the matrix by K elements.




Sample Input 1

4 4

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

3


Sample Output 1

13 9 5 1

14 7 11 2

15 6 10 3

16 12 8 4


Sample Input 2

3 4

1 2 3 4

10 11 12 5

9 8 7 6

2


Sample Output 2

9 10 1 2

8 11 12 3

7 6 5 4


Triplet Sum

Given an array n integers, find and print all the unique triplets (a, b, c) in the array which give the sum K. (a+b+c=K).Input


The first line of the input will be space separated integers, denoting the elements of the array. The second line of the input will be an integer denoting the required sum KOutput


The output should be multiple lines, each line containing a unique triplet. The elements of the triple must be sorted in increasing order and all the triplets printed must be sorted in increasing order. Print "No Matching Triplets Found" if there are no triplets with the given sum.Explanation


When the given array is [0, 1, 2, 3, 5, 7, 13, 17, 19, 19] and the required sum is 22, the triplets (0, 3, 19), (0, 5, 17), (1, 2, 19), (2, 3, 17) and (2, 7, 13) have the given sum 22.


Sample Input 1

0 12 17 8 9 21

29


Sample Output 1

(0, 8, 21)

(0, 12, 17)

(8, 9, 12)


Sample Input 2

0 1 2 3 5 7 13 17 19 19

22


Sample Output 2

(0, 3, 19)

(0, 5, 17)

(1, 2, 19)

(2, 3, 17)

(2, 7, 13)




Non-Adjacent Combinations of Two Words

Given a sentence as input, find all the unique combinations of two words and print the word combinations that are not adjacent in the original sentence in lexicographical order.Input


For example, if the given sentence is "python is a programming language", the possible unique combination of two are (a, is), (a, language), (a, programming), (a, python), (is, language), (is, programming), (is, python), (language, programming), (language, python), (programming, python). Out of these the combinations, (a, is), (a, programming), (is, python), (language, programming) are not valid as they contain words that are adjacent in the given sentence. So the output should be

a language

a python

is language

is programming

language python

programming python


Sample Input 1

raju always plays cricket


Sample Output 1

always cricket

cricket raju

plays raju


Sample Input 2

to be or not to be


Sample Output 2

be be

be not

or to

to to




Rotate Matrix Rings

Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.Input


For example, if the given M and N are 4 and 4 respectively. If the matrix elements are

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

If the given K is 3. Rotate each ring of the matrix by 3 elements.

In the above matrix, the elements (1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5) is a ring, similarly, the elements (6, 7, 11, 10) will make a ring.

Therefore, by rotating each ring in clockwise direction by 3 elements will give (13, 9, 5, 1, 2, 3, 4, 8, 12, 16, 15, 14) and (10, 6, 7, 11). So the output should be

13 9 5 1

14 7 11 2

15 6 10 3

16 12 8 4


Sample Input

3 4

1 2 3 4

10 11 12 5

9 8 7 6

2


Sample Output

9 10 1 2

8 11 12 3

7 6 5 4




1.      >>> 2- 2



2.      >>> 2 -(2-)

 File "<stdin>", line 1

   2 -(2-)

         ^

SyntaxError: invalid syntax


3.      >>> (0+1)-9(1/2)

<stdin>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?

Traceback (most recent call last):

 File "<stdin>", line 1, in <module>

TypeError: 'int' object is not callable


Give explanation to these results experimented in python above.

Write a python program to achieve Advanced Encryption Standard 128 bit key length encoding and decoding of text.

Program should be algorithm based rather than using any library function. Write both ENCODING and DECODING.  

Input text

“To be, or not to be, that is the question: Whether 'tis nobler in the mind to suffer

The slings and arrows of outrageous fortune,

Or to take arms against a sea of troubles

And by opposing end them. To die—to sleep,

No more; and by a sleep to say we end

The heart-ache and the thousand natural shocks

That flesh is heir to: 'tis a consummation

Devoutly to be wish'd. To die, to sleep;

To sleep, perchance to dream—ay, there's the rub:

For in that sleep of death what dreams may come,

When we have shuffled off this mortal coil,

Must give us pause—there's the respect

That makes calamity of so long life.

When he himself might his quietus make

With this regard their currents turn awry

And lose the name of action.”




LATEST TUTORIALS
APPROVED BY CLIENTS