AcWing 745. 数组的右上半部分 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-16 03:30:52
,
所有人可见
,
阅读 204
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 <= i; j ++)
cin.nextDouble();
for (int j = i + 1; j < 12; j++)
{
sum += cin.nextDouble();
count += 1;
}
}
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));
}
}