๐ฉ๐ปProgramming/Coding Test
[C#] [BOJ#1546] ๋๋จธ์ง - ํ๊ท
taesooya
2022. 7. 30. 23:41
https://www.acmicpc.net/problem/1546
2741๋ฒ: N ์ฐ๊ธฐ
์์ฐ์ N์ด ์ฃผ์ด์ก์ ๋, 1๋ถํฐ N๊น์ง ํ ์ค์ ํ๋์ฉ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
www.acmicpc.net
My Solution
float int ํต์ผํด์ผ์ง ใ ใ
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int m = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
string[] ss = s.Split();
float[] arr = Array.ConvertAll<string, float>(ss, float.Parse);
Array.Sort(arr);
float sum = 0;
float result = 0;
for (int i = 0; i < arr.Length; i++)
{
sum += ((arr[i] / arr[m-1]) * 100);
}
result = sum / m;
Console.WriteLine(result);
}
}
}
Solution
float์ด๋ int๋ฅผ ๊ฐ์ด ๊ณ์ฐํ๋ คํจ...
์ด๋ฐ ์ฌ์ํ ์ค์๋.. ๊ธ์ง...
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int m = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
string[] ss = s.Split();
float[] arr = Array.ConvertAll<string, float>(ss, float.Parse);
Array.Sort(arr);
float sum = 0;
float result = 0;
for (int i = 0; i < arr.Length; i++)
{
sum += ((arr[i] / arr[m-1]) * 100);
}
result = sum / m;
Console.WriteLine(result);
}
}
}