Math Quiz
Write a program to print the following,
Sample Input 1
1 3 4 5 6
5
3 5
Sample Output1
12
Ordered Matrix
Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.
Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.
Output
The output should be M lines containing the ordered matrix.
Note: There is a space at the end of each line.
Explanation
For example, if the given M is 3 and N is 3, read the inputs in the next three lines if the numbers given in the next three lines are the following.
1 20 3
30 10 2
5 11 15
By ordering all the elements of the matrix in increasing order, the ordered matrix should be
1 2 3
5 10 11
15 20 30
Sample Input 1
3 3
1 20 3
30 10 2
5 11 15
Sample Output 1
1 2 3
5 10 11
15 20 30
Sample Input 2
2 5
-50 20 3 25 -20
88 17 38 72 -10
Sample Output 2
-50 -20 -10 3 17
20 25 38 72 88
Sum of Non-Diagonals
As the creative content member of your newspaper company, you are given the task to publish a puzzle in your local newspaper. For a given MxM integer matrix, the task is to print the sum of all elements other than the diagonal elements,Both the diagonals are to be excluded.
Input
The first line of input is a positive integer M.
The next M lines of input contain M space-separated integers.
Output
The output is an integer that represents the sum of all the numbers in the matrix as mentioned above.
Sample Input1
3
4 1 3
2 5 6
1 2 3
Sample Output1
11
Sample Input2
5
1 2 2 3 3
4 4 5 6 7
9 8 7 6 5
9 2 3 8 8
-4 -2 -2 4 -7
Sample Output2
63
Friend and Enemy
A group of F friends went to a haunted house.Each member was given a shirt with a number on it ranging from 1 to F. As they entered the haunted house, one of them was kidnapped and an enemy joined them.But unfortunately, the enemy didn't wear the shirt with the same number as the kidnapped one, instead wore the same as some other person.Find the numbers on the shirts of the enemy and the kidnapped person.
Input
The input is a single line containing space-separated positive integers from 1 to F.
Output
The output should be a single line containing the shirt numbers of the enemy and kidnapped person separated by a space.
Explanation
The given array is 3 1 5 2 1
In the range from 1 to 5, the number 1 has occured twice and 4 is the missing number. So, 1 belongs to the enemy's shirt, and 4 belongs to kidnapped.Hence, the output should be 1 4.
Sample Input1
3 1 5 2 1
Sample Output1
1 4
Sample Input2
1 2 2 4
Sample Output2
2 3
Strict Sentence
A sentence is called Strict sentence if it contains all unique words.You can make a sentence strict by removing some words from it such that all remaining words are unique.
You are given a sentence S. You need to write a program to make it strict and print the longest strict sentence possible(Order of words in the given sentence should be preserved).
Note: Words are case-insensitive. For example, Apple, apple, aPPle etc.. are considered the same word.
Input
The first line contains a string S.
Output
The output contains a string which is the longest strict sentence possible.
Explanation
For S = my name is usha my native place is hyderabad.
my and is are not unique words.After removing my and is, the longest possible strict sentence is my name is usha native place hyderabad. So the output should be my name is usha native place hyderabad.
Sample Input1
my name is usha my native place is hyderabad
Sample Output1
my name is usha native place hyderabad
Midterm Questions-checkpoint.ipynb
Midterm Questions-checkpoint.ipynb_
𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 1
As you are a student of university now, you need to ensure your assignments
are plagiarism-free. To do this, you decide to design a simple plagiarism
checker. Your checker will take 2 strings as input. Then it will compare
the 2 strings and check how many words they have in common. Then, print the
percentage in common, by calculating:
(No. of words in common / (No of words in string 1 + No of words in string 2)) * 100.
If the calculated plagiarism is greater than or equal to 30%,
print “Plagiarism detected.” Otherwise, print “Good job!”.
Note: you need to compare “words” not individual characters. You can
consider that all characters in both inputs will be in only lowercase or
uppercase.
6. Write a Python program that reads a number and finds the sum of the series of 1 +11 + 111 + 1111 + ….+N terms.
=====================================================
Sample Input1:
5
Sample Output1:
1 + 11 + 111 + 1111 + 11111
The Sum is: 1234
4. Write a Python program to Capitalize the first character of each word in a String [You cannot use the built-in upper() function]
Sample Input:
I love python programming
Sample Output: I Love Python Programming
2. Write a Python program to find the largest and smallest word in a string.
[you are not allowed to use max() and min()]
Sample Input :
It is a string with the smallest and largest word.
Sample Output :
The largest word is “smallest” and the smallest word is 'a'.
you are given a undireevted tree with n nodes numbered from 0ton-1 each node has a value represented by the array arr of length n you have to divode this tree into two components by removing a single edge moreover you need to ensure the bitwise and of both trees obtained is same find total number of ways to divide the given tree