코딩테스트 문제 풀이/[백준] 기본 수학1(9)
-
[C#] 백준 1193번 분수찾기
정답 코드 : using System; namespace _3 { internal class Program { static void Main(string[] args) { int input = Convert.ToInt32(Console.ReadLine()); int x, y; int xValue = 1; int yValue = 1; int count = 1; bool isOdd = false; bool go = false; //대각선으로 내려가겠다 bool turn = false; //아래 혹은 옆으로 이동하는 작업을 했는가 판단해주는 값 int check; while (count < input)//(0,1), 2/1, isXzero == true { if(xValue == 1 || yValue ==1)..
2021.12.21 -
[C#] 백준 2292번 벌집
정답 코드 : using System; using System.Collections.Generic; namespace _2 { class Program { static void Main(string[] args) { int input = Convert.ToInt32(Console.ReadLine()); int n = 1; int k = n - 1; int output = 1; while (input > output) { output += 6 * (n-1); n++; } if (input == 1) Console.WriteLine(n); else Console.WriteLine(n-1); } } } 이 문제에는 규칙이 있다 바로 값들의 공차가 일정한 계차수열인 것이다. 따라서 계차수열을 구해주는 코드를 추..
2021.12.21 -
[C#] 백준 1712번 손익분기점
정답 코드 : using System; using static System.Console; namespace ConsoleApp3 { class Program { public static void Main(string[] args) { string abc = ReadLine(); string[] word = abc.Split(' '); //21억까지 int로 받을 수 있다 즉 21억까지 계속 계산하는 포문으로 만들게되면 안된다는 의미이다. int a = int.Parse(word[0]); int b = int.Parse(word[1]); int c = int.Parse(word[2]); if (b >= c) //b > c이면 아무리 계속 팔아도 순익분기점을 넘길 수 없음 { WriteLine(-1); r..
2021.12.21