#C6392. Sort Regions by Power Level
Sort Regions by Power Level
Sort Regions by Power Level
You are given a list of region numbers. Each region number is a positive integer. The power level of a number is defined as the sum of the squares of its digits. In other words, for a number \( n \) with digits \( d_1,d_2,\ldots,d_k \), its power level is given by:
\(\displaystyle P(n)=\sum_{i=1}^{k}d_i^2\)
Your task is to sort the region numbers in increasing order based on their power levels. In case two region numbers have the same power level, they should be sorted by their numerical value in increasing order.
The input consists of several test cases. For each test case, you will be given a single line containing space-separated region numbers. You need to output the sorted region numbers in one line for each test case.
inputFormat
The input begins with an integer ( T ) representing the number of test cases. Each of the next ( T ) lines contains a list of space-separated region numbers. Each region number is a positive integer.
outputFormat
For each test case, output a single line containing the region numbers sorted by their power levels in increasing order. If two numbers have the same power level, sort them in increasing numerical order.## sample
1
12 34 56 78
12 34 56 78