(UVA) Parking - Solution
import java.io.*;
import java.util.*;
class Main {
public static void process() throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
int numCases = sc.nextInt();
for (int i = 0; i < numCases; i++) {
int numStores = sc.nextInt();
int smaller = 10000;
int bigger = -1;
for (int j = 0; j < numStores; j++) {
int store = sc.nextInt();
if (store > bigger) {
bigger = store;
}
if (store < smaller) {
smaller = store;
}
}
System.out.println((bigger-smaller)*2);
}
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
import java.util.*;
class Main {
public static void process() throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
int numCases = sc.nextInt();
for (int i = 0; i < numCases; i++) {
int numStores = sc.nextInt();
int smaller = 10000;
int bigger = -1;
for (int j = 0; j < numStores; j++) {
int store = sc.nextInt();
if (store > bigger) {
bigger = store;
}
if (store < smaller) {
smaller = store;
}
}
System.out.println((bigger-smaller)*2);
}
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
Comments
Post a Comment