プログラマメモ2 - programmer no memo2

2636 - コンセントもんだい 2011/06/14

ひさしぶりのPKU

ちょーかんたんなもんだい

2636 -- Electrical Outlets

package p2636;

import java.io.IOException;
import java.util.Scanner;

public class Main {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
int c = scanner.nextInt();
scanner.nextLine();
for (int i = 0; i < c; i++) {
String line = scanner.nextLine();
System.out.println(a(line));
}
}

static int a(String line) {

String[] ss = line.split(" ");
int a = 0;
if (1 < ss.length) {
a += Integer.parseInt(ss[0]) - 1;
} else {
a += Integer.parseInt(ss[0]);
}
for (int i = 1; i < ss.length - 1 ; i++) {
a += Integer.parseInt(ss[i]) - 2;
}

if (1 < ss.length) {
a += Integer.parseInt(ss[ss.length-1]) ;
} else {

}
return a;
}
}

: