A class octopus has a dummy head which has four pointers – left, right, top and bottom. You have to build linked list in these 4 directions depending on the input commands. There will be four types of commands – L, R, T and B. Their specifications are given below:
L x: insert x in the left link list // Where x is an integer number.
R x: insert x in the right link list
T x: insert x in the top link list
B x: insert x in the bottom link list
Input: Test case will start with a number n indicating the number of lines following it.
Output: you have to give output that which link list (Left, Right, Top and Bottom) has maximum sum of values. See the sample input and output.
Sample input
14
L 3
L 15
L 1
R 17
T 9
T 10
B 13
T 5
L 8
R 3
R 12
B 2
B 3
B 4
Sample output
Right Link List Has Maximum Sum 32
W pattern with *
Write a program to print
The first line is an integer
For
N = 5The output should be
#using python3
# The client Sends All Data to server and then Closes the Connection,
#without expecting reply.
# Using UDP datagrams for communication, then the protocol itself will
#deliver your data in discrete and identifiable chunks.
# Sending data over a stream but delimited as length-prefixed blocks.
import socket, struct
from argparse import ArgumentParser
header_struct = struct.Struct('!I') # messages up to 2**32 - 1 in length
def client(address):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(address)
sock.shutdown(socket.SHUT_RD)
put_block(sock, b'Beautiful is better than ugly.')
put_block(sock, b'Explicit is better than implicit.')
put_block(sock, b'Simple is better than complex.')
put_block(sock, b'')
sock.close()
Write a program to print out all Armstrong numbers between a range of numbers entered by user. The following is a sample of output:
Sample 1
enter the range of numbers :10 100
the Armstrong numbers are:
No Armstrong Numbers found:
sample 2
enter the range of numbers : 100 2000
the Armstrong Numbers are :
153
370
371
407
1634
Shaded Diamond
Given an integer value
N as input, write a program to print a shaded diamond of 2*N -1 rows using an asterisk(*) character as shown below.
Note: There is a space after each asterisk (*) character.
Input
The first line of input is an integer
N.
Explanation
In the given example
N = 5. Therefore, the output should be
*
* *
* * *
* * * *
* * * * *
* *
* *
* *
*
Sample Input 1
6
Sample Output 1
*
* *
* * *
* * * *
* * * * *
* * * * * *
* *
* *
* *
* *
*
Sample Input 2
5
Sample Output 2
*
* *
* * *
* * * *
* * * * *
* *
* *
* *
*
Number Diamond
Given an integer
N as input, write a program to print a number diamond of 2*N -1 rows as shown below.
Note: There is a space after each number.
Input
The first line of input is an integer
N.
Explanation
In the given example, the number of rows in the diamond is
5.
So, the output should be
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Sample Input 1
5
Sample Output 1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Sample Input 2
4
Sample Output 2
1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
Multiples of 3
You are given
N inputs. Print the numbers that are multiples of 3.
Input
The first line of input is an integer
N. The next N lines each contain an integer as input.
Explanation
In the given example, there are
6 inputs. 1, 2, 3, 5, 9, 6. The numbers 3, 9, 6 are multiples of 3.
So, the output should be
3
9
6
Sample Input 1
6
1
2
3
5
9
6
Sample Output 1
3
9
6
Sample Input 2
4
1
3
6
8
Sample Output 2
3
6