题目链接:
计算机软件能力认证考试系统http://118.190.20.162/view.page?gpid=T129
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int i;
int pre = scanner.nextInt();
if(n == 1) {
System.out.println(pre);
System.out.println(pre);
}else{
int a;
int min = pre, max = pre;
for(i = 1; i < n; i++){
a = scanner.nextInt();
max += a;
if(a == pre){
min += 0;
}else{
min += a;
pre = a;
}
}
System.out.println(max);
System.out.println(min);
}
}
}
|