AcWing 749. 数组的上方区域 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-16 03:51:31
,
所有人可见
,
阅读 228
Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
String s = cin.next();
cin.nextLine();
double sum = 0.0;
int count = 0;
for (int i = 0; i < 5; i ++ )
{
for (int j = 0; j < i + 1; j ++ )
cin.nextDouble();
for (int j = i + 1; j < 11 - i; j ++)
{
sum += cin.nextDouble();
count += 1;
}
for (int j = 11 -i; j < 12; j++)
cin.nextDouble();
}
if (s.compareTo("S") == 0 )
System.out.println (String.format("%.1f", sum));
if (s.compareTo("M") == 0)
System.out.println (String.format("%.1f", sum/count));
}
}