Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* package codechef; // don't place package name! */
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- /* Name of the class has to be "Main" only if the class is public. */
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception, NumberFormatException, IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- // Read the number of test cases
- int testCases = Integer.parseInt(reader.readLine().trim());
- for (int i = 0; i < testCases; i++) {
- // Read the number of values in the list
- int[] abc = new int[3];
- String[] line = reader.readLine().split(" ");
- for (int j = 0; j < 3; j++) {
- abc[j] = (Integer.parseInt(line[j]));
- }
- int n = Integer.parseInt(reader.readLine());
- // Read the list of values
- String[] line1 = reader.readLine().split(" ");
- int[] values = new int[n];
- for (int j = 0; j < n; j++) {
- values[j] = (Integer.parseInt(line1[j]));
- }
- sortedSquares(values, abc);
- }
- // int c = 1;
- // for (int[] values : arr) {
- // c++;
- // }
- }
- public static int[] sortedSquares(int[] nums, int[] nums2) {
- int i = 0;
- for (; i < nums.length; i++) {
- nums[i] = (nums2[0] * nums[i] * nums[i]) + (nums2[1] * nums[i]) + nums2[2];
- }
- for (int p = 1; p < nums.length; p++) {
- int key = nums[p];
- int j = p - 1;
- while (j >= 0 && nums[j] > key) {
- nums[j + 1] = nums[j];
- j--;
- }
- nums[j + 1] = key;
- }
- for (int l : nums) {
- System.out.print(l + " ");
- }
- System.out.println();
- return nums;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement