본문 바로가기
반응형

코딩테스트 준비/백준 C#161

백준 C# - 2609 +) 풀이 풀이 01 최대 공약수 for(int i = 1; i 2023. 10. 31.
백준 C# - 10430 using System; namespace baek2 { class Program { static void Main(string[] args) { string word = Console.ReadLine(); string[] token = word.Split(); int A = int.Parse(token[0]); int B = int.Parse(token[1]); int C = int.Parse(token[2]); Console.WriteLine((A + B) % C); Console.WriteLine(((A % C) + (B % C)) % C); Console.WriteLine((A * B) % C); Console.Write(((A % C) * (B % C)) % C); } } } 2023. 10. 31.
백준 C# - 11656 +) 풀이 풀이 01 앞에서부터 하나씩 뺀 다음 배열에 넣기 일단 접미사를 배열에 넣는 순서는 중요하지 않다. 나중에 Sort시켜주기 때문이다. 그러므로 앞에서 하나씩 뺀 다음 배열에 넣어준다. for(int i = 0; i 0) sb.Remove(0, 1); } 02 Sort시켜주기 Array.Sort(list); 03 출력하기 foreach(string s in list) { Console.WriteLine(s); } 코드 전문 using System; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { string word = Console.ReadLine(); StringBuilder sb = new St.. 2023. 10. 27.
백준 C# - 10842 +) overflow문제 아래와 같은 코드로 제출을 했는데 계속 overflow에러가 떴다. using System; namespace baek2 { class Program { static void Main(string[] args) { string word = Console.ReadLine(); string[] token = word.Split(); string AB = token[0] + token[1]; string CD = token[2] + token[3]; Console.Write($"{int.Parse(AB) + int.Parse(CD)}"); } } } 문제의 원인 int.Parse 문제에서와 같이 문자열 입력이 1 ≤ A, B, C, D ≤ 1,000,000 이러한 조건이 있다. 문자열을 int.Parse 메서.. 2023. 10. 27.
백준 C# - 11655 +)풀이 풀이 처음에는 isLetter를 사용해서 풀려고 했다. 아스키코드를 사용해서 풀려고 하다보니 대문자와 소문자를 나누어서 풀어야 겠다는 생각이 들었다. 01 소문자 if (Char.IsLower(c)) { num = (int)c + 13; if (num > 122) num -= 26; sb.Append((char)num); continue; } 02 대문자 if(Char.IsUpper(c)) { num = (int)c + 13; if (num > 90) num -= 26; sb.Append((char)num); continue; } 03 그 외 else { sb.Append(c); continue; } 코드 전문 using System; using System.Text; namespace baek2 { c.. 2023. 10. 27.
백준 C# - 2743 딱 떠오른 코드 using System; namespace baek2 { class Program { static void Main(string[] args) { string word = Console.ReadLine(); int num = 0; foreach(char c in word) { num++; } Console.WriteLine(num); } } } 개선한 코드 using System; namespace baek2 { class Program { static void Main(string[] args) { string word = Console.ReadLine(); Console.WriteLine(word.Length); } } } 2023. 10. 27.
반응형