#C14020. Square Integers
Square Integers
Square Integers
You are given a list of tokens. The first token is an integer (N) that denotes the number of subsequent tokens. These tokens can represent integers or other non-integer values. For each token that is a valid integer, compute its square (i.e. compute (x^2) for an integer (x)). Ignore tokens that are not valid integers. However, if any valid integer is negative (i.e. (x < 0)), immediately output the error message "Negative integers are not allowed". If the input does not start with a valid integer, then output "Input must be a list".
Your task is to read the input from standard input (stdin) and write the appropriate output to standard output (stdout).
inputFormat
A single line containing space-separated tokens. The first token is an integer (N) representing the number of tokens that follow. Then (N) tokens follow. If the first token is not a valid integer, output the error: "Input must be a list".
outputFormat
If the input is valid and no negative integer is encountered, output the squares of all valid (non-negative) integers in the order they appear, separated by a single space. If any valid integer is negative, output "Negative integers are not allowed".## sample
4 1 2 3 4
1 4 9 16