코딩테스트 문제 풀이(88)
-
C# 백준 2581번 소수
코드 : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _2 { internal class Program { static void Main(string[] args) { int M = Convert.ToInt32(Console.ReadLine()); int N = Convert.ToInt32(Console.ReadLine()); int number = 0; int sum = 0; int[] array = new int[1]; array[0] = 0; for (int i = M; i
2022.01.03 -
C# 백준 1978번 소수찾기
코드 : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _1 { internal class Program { static void Main(string[] args) { //1 3 5 7 전체길이 = 4, number = 1, 출력 = 3 int N = Convert.ToInt32(Console.ReadLine()); string input = Console.ReadLine(); string[] inputdata = input.Split(' '); int number = 0; //소수가 아닌값들을 찾아서 전체 길이에서 빼기 fo..
2022.01.03 -
[C#] 백준 1011번 Fly me to the Alpha Centauri
정답 코드 : using System; namespace _9 { class Program { static void Main(string[] args) { int T = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < T; i++) { string input = Console.ReadLine(); string[] inputData = input.Split(' '); long x = Convert.ToInt32(inputData[0].ToString()); long y = Convert.ToInt32(inputData[1].ToString()); long an = 2; long k = 2; long d = y - x; long count = 1; lon..
2021.12.22 -
[C#] 백준 10757번 큰 수 A+B
정답 코드 : using System; using System.Numerics; namespace _8 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string[] inputData = input.Split(' '); BigInteger idx1 = BigInteger.Parse(inputData[0]); BigInteger idx2 = BigInteger.Parse(inputData[1]); Console.WriteLine(idx1 + idx2); } } } 10의 1만승은 데이터타입으로 표현이 불가능하다. C#에는 이런 큰값 계산을 위한 메소드가 있다. BigInteger를 사용하면 그냥 계..
2021.12.21 -
[C#] 백준 2839번 설탕 배달
정답 코드 : using System; namespace _7 { class Program { static void Main(string[] args) { int input = Convert.ToInt32(Console.ReadLine()); int inputSave = input; int divisionFive = input / 5; int min = 10000; if (input % 3 == 0 && min > input / 3) min = input / 3; for (int i = 1; i < divisionFive + 1; i++) { input = inputSave; input -= 5 * i; if(input % 3 == 0) { int divisionThree = input / 3; if(m..
2021.12.21 -
[C#] 백준 2775번 부녀회장이 될테야
정답 코드 : using System; namespace _6 { class Program { static void Main(string[] args) { int T = Convert.ToInt32(Console.ReadLine()); for (int K = 0; K < T; K++) { int k = Convert.ToInt32(Console.ReadLine()); //층 int n = Convert.ToInt32(Console.ReadLine()); //호 int person = 0; int[,] room = new int[n, k + 1]; //4층에 3호를 구하고 싶으면 0층 1호를 (1,1)으로 기준점을 잡고 (3,4)를 구한다. int[] Floor0 = new int[n]; for (int ..
2021.12.21