본문 바로가기

Programming Practice/C#6

CS0161 오류 클래스를 활용하여 계산기 코드를 짜고 있던 중에 거슬리는 CS0161에러. 저 에러 하나 때문에 빌드가 안 되고 있던 중이라 대체 뭐가 문제일까 검색해봤다.not all code paths return a value. 말 그대로 모든 반환값이 리턴되진 않는다 뭐 그런 뜻.해결법은 아주 간단했다. switch (op){ case Operator.Add: return n1 + n2; case Operator.Subtract: return n1 - n2; case Operator.Multiply: return n1 * n2; case Operator.Divide: if (n2 == 0) { Console.WriteLine("0으로 나눌 수 없음."); return 0; .. 2025. 6. 8.
백준 3003 킹, 퀸, 룩, 비숍, 나이트, 폰 C# using System; namespace ChessSet{ class Chess{ static void Main(){ string[] input = Console.ReadLine().Split(); int[] w = {1, 1, 2, 2, 2, 8}; for(int i = 0; i < input.Length; i++){ w[i] -= int.Parse(input[i]); } foreach(int j in w) Console.Write(j.ToString() + " "); } } } https://www.acmicpc.net/problem/3003 3003번: 킹, 퀸, 룩, 비숍, 나이트, 폰 첫째 줄에 동혁이가 찾은 흰색 킹, 퀸, 룩, 비숍, 나이트, 폰의 개수가 주어진다. 이 값은 0보다 크거나 .. 2023. 9. 16.
백준 2744 대소문자 바꾸기 C# https://www.acmicpc.net/problem/2744 2744번: 대소문자 바꾸기 영어 소문자와 대문자로 이루어진 단어를 입력받은 뒤, 대문자는 소문자로, 소문자는 대문자로 바꾸어 출력하는 프로그램을 작성하시오. www.acmicpc.net using System; public class Test { public static void Main() { string s = Console.ReadLine(); string res = ""; for(int i = 0; i < s.Length; i++){ char current = s[i]; //current값이 대문자인지 체크하고 맞으면 소문자로, 틀리면 대문자로. res += char.IsUpper(current) ? char.ToLower(s[i.. 2023. 9. 10.
백준 2738 행렬 덧셈 C# https://www.acmicpc.net/problem/2738 2738번: 행렬 덧셈 첫째 줄에 행렬의 크기 N 과 M이 주어진다. 둘째 줄부터 N개의 줄에 행렬 A의 원소 M개가 차례대로 주어진다. 이어서 N개의 줄에 행렬 B의 원소 M개가 차례대로 주어진다. N과 M은 100보다 작거나 같 www.acmicpc.net using System; namespace Baekjoon { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(); int n = int.Parse(s[0]); int m = int.Parse(s[1]); int[,] A = new int[n, m]; int[,] B = ne.. 2023. 9. 10.
C# 기본2 백준 C# 2753, 9498, 1330, 14681, 2884, 2525, 3003 if문 예제 // 2753 using System; namespace YoonNyeon{ class Program{ static void Main(){ int y = int.Parse(Console.ReadLine()); if((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) Console.WriteLine("1"); else Console.WriteLine("0"); } } } // 9498 using System; namespace Score{ class Program{ static void Main(){ int A = int.Parse(Console.ReadLine()); if (A.. 2022. 11. 16.
C# 기본 C# 기본 Hello World 출력 // using => namespace 가져오기 // namespace는 같은 그룹의 클래스를 묶음 // Console.WriteLine 메소드는 System이란 namespace에 소속된 Console 클래스의 메소드 // System.Console은 namespace가 System이다. 이외에도 System에 소속된 다양한 클래스 있음 // *** 클래스의 이름은 namespace 안에서 유일해야 함 *** // Visual Studio에서 폴더 이름과 namespace가 같아야 함 // 파일 명은 class 이름과 동일하게 // 함수와 클래스에는 PascalCase, 변수와 파라미터에는 camelCase using System; namespace HelloWor.. 2022. 11. 16.