#C12190. Squares of Positive Integers
Squares of Positive Integers
Squares of Positive Integers
You are given a list of integers. Your task is to filter out the non-positive integers and calculate the square of each positive integer. Then, output the result as a dictionary (or map) where each key is the positive integer and the corresponding value is its square. The keys in the output must be sorted in ascending order.
Note: The dictionary should be printed in the following format: {key1: value1, key2: value2, ...}
. If there are no positive integers, output {}
.
Example:
Input: 3 1 2 3</p>Output: {1: 1, 2: 4, 3: 9}
The squaring operation is given by the formula: \( n^2 \), where \( n \) is a positive integer.
inputFormat
The first line contains an integer ( n ) denoting the number of integers. The second line contains ( n ) space-separated integers.
outputFormat
Output a dictionary where each positive integer from the input is a key and its value is the square of the integer. The keys must be printed in ascending order. For example, if the input is:
3 1 2 3
then the output should be:
{1: 1, 2: 4, 3: 9}## sample
3
1 2 3
{1: 1, 2: 4, 3: 9}