글
백준 1546번 평균(JAVA, C#) BufferedReader
자바
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double arr[] = new double[in.nextInt()];
for(int i = 0; i < arr.length; i++)
{
arr[i] = in.nextDouble();
}
in.close();
double sum = 0;
Arrays.sort(arr);
for(int i = 0; i < arr.length; i++)
{
sum += ((arr[i] / arr[arr.length-1]) * 100);
}
System.out.print(sum / arr.length);
}
}
buffered
///////
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
double arr[] = new double[Integer.parseInt(br.readLine())];
StringTokenizer st = new StringTokenizer(br.readLine()," ");
for(int i = 0; i < arr.length; i++)
{
arr[i] = Double.parseDouble(st.nextToken());
}
double sum = 0;
Arrays.sort(arr);
for(int i = 0; i < arr.length; i++)
{
sum += ((arr[i] / arr[arr.length - 1]) * 100);
}
System.out.print(sum/arr.length);
/////////////////////
C#
using System;
namespace Baekjoon {
class Program {
static void Main(string[] args) {
int length = int.Parse(Console.ReadLine());
double[] arr = new double[length];
string[] numbers = Console.ReadLine().Split();
for(int i = 0; i<length; i++)
{
arr[i] = double.Parse(numbers[i]);
}
double sum = 0;
Array.Sort(arr);
for(int i = 0; i < arr.Length; i++)
{
sum += ((arr[i] / arr[arr.Length-1]) * 100);
}
Console.WriteLine(sum / arr.Length);
}
}
}
'백준 프로그래밍' 카테고리의 다른 글
백준 4344번 평균은 넘겠지(JAVA, C#) %.3f%%\n / 100:F3}% (0) | 2023.02.18 |
---|---|
백준 8958번 OX퀴즈(JAVA, C#) charAt(), array[].length() (0) | 2023.02.18 |
백준 3052번 나머지(JAVA, C#) (0) | 2023.02.18 |
백준 5597번 과제 안 내신 분(JAVA, C#) (0) | 2023.02.16 |
백준 2562번 최댓값(JAVA, C#) (0) | 2023.02.16 |