AcWing 747. 数组的左上半部分 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-16 03:37:59
,
所有人可见
,
阅读 220
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 < 12; i ++ )
{
for (int j = 0; 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));
}
}