BEST
-
C# 1260번 DFS와 BFS
코드 : using System; using System.Collections.Generic; namespace _1 { class Program { static int[] input; static int N; static int M; static int V; static public int[,] map = new int[1001, 1001]; static public bool[] visited = new bool[1001]; static public Queue queue = new Queue(); static public Stack stack = new Stack(); static void Reset() { for (int i = 1; i
-
C# 2110번 공유기 설치
코드 : using System; namespace _5 { class Program { static void Main(string[] args) { int[] N_C = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = N_C[0]; int C = N_C[1]; int[] X = new int[N]; for (int i = 0; i < N; i++) { X[i] = Convert.ToInt32(Console.ReadLine()); } Array.Sort(X); long start = 1; long end = X[^1]; //mid의 의미는 공유기간의 거리 //가장 인접한 두 공유기 사이의 거리를 최대로 하라는 말은 //선택한 공유기..
-
C# 2805번 나무 자르기
코드 : using System; namespace _4 { class Program { static void Main(string[] args) { int[] N_M = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = N_M[0]; int M = N_M[1]; int[] wood = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); Array.Sort(wood); long start = 1; long end = wood[^1]; long mid = (start + end) / 2; long sum = 0; while (start = M) { start = mid+1; mid..
-
[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를 사용하면 그냥 계..
-
[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 ..
-
[Unity] Unity의 enabled, isActiveAndEnabled 및 activeInHierarchy의 차이점
https://stackoverflow.com/questions/40708014/difference-between-enabled-isactiveandenabled-and-activeinhierarchy-in-unity
-
C# 1012번 유기농 배추
코드 : using System; using System.Collections.Generic; namespace _4 { class Program { static int T,M,N,K; //맵 저장 행렬 static int[,] map = new int[51, 51]; //방문 확인 행렬 static bool[,] visited = new bool[51, 51]; static Queue queue = new Queue(); static int[] dx = { -1, 1, 0, 0 }; static int[] dy = { 0, 0, -1, 1 }; //배추흰지렁이 수 static int count; static void Reset() //초기화 { count = 0; for (int i = 0; i < M..
-
메타버스[개발#1] 아바타 선택 및 닉네임 설정, PlayerPref활용
목표 : 사용자가 원하는 아바타 선택이 가능하도록 하고 닉네임을 입력하여 식별이 가능하도록 한다. 닉네임 입력시 저장 후 캐릭터 위에 생성되도록 설정 public void ConnectToServer() { if (NameText.text == "") { Debug.Log("null"); } else { InputField.SetActive(false); toggleGroup.SetActive(false); Debug.Log("서버에 연결을 시도합니다."); PhotonNetwork.ConnectUsingSettings(); // 서버연결 if (PlayerPrefs.HasKey("Name")) PhotonNetwork.NickName = PlayerPrefs.GetString("Name"); } } 닉..
NEWS
-
[C#] Find() vs FirstOrDefault()
C#에서 Find와 FirstOrDefault 메서드는 컬렉션에서 특정 조건을 만족하는 요소를 검색하는 데 사용됩니다. 그러나 이 두 메서드는 서로 다른 성능 특성을 가지고 있으며 사용 시 고려해야 할 사항이 있습니다. List.Find 메서드: List 클래스에서 사용할 수 있으며, 리스트에서 첫 번째로 조건을 만족하는 요소를 검색합니다. 선형 검색을 수행하며, 리스트의 처음부터 끝까지 요소를 하나씩 확인합니다. 성능은 리스트의 크기에 비례하므로 대규모 리스트에서는 성능 저하가 있을 수 있습니다. Enumerable.FirstOrDefault 메서드: IEnumerable 인터페이스를 구현하는 모든 컬렉션에서 사용할 수 있습니다. 조건을 만족하는 첫 번째 요소를 검색하며, 내부적으로 반복자를 사용하여 ..
2023.09.05 19:03 -
.Any()
IEnumerable를 구현하는 일반적인 컬렉션: 대부분의 컬렉션, 예를 들어 리스트(List), 배열(T[]) 등은 IEnumerable를 구현합니다. 이러한 컬렉션에서 Any 메서드는 컬렉션의 각 요소를 순차적으로 확인하면서 조건을 만족하는 요소를 찾으면 검색을 중지하고 true를 반환합니다. 이 경우, 선형 검색이 수행됩니다. ICollection를 구현하는 컬렉션: 일부 컬렉션, 예를 들어 HashSet, Dictionary 등은 ICollection를 구현하며, 이 인터페이스는 Count 속성을 가지고 있습니다. 이러한 컬렉션에서 Any 메서드는 컬렉션의 Count 속성을 확인하여 요소의 존재 여부를 결정합니다. 따라서 실제로 모든 요소를 순차적으로 확인하지 않고도 빠르게 true 또는 fals..
2023.09.05 19:01 -
[Unity] Unity의 enabled, isActiveAndEnabled 및 activeInHierarchy의 차이점
https://stackoverflow.com/questions/40708014/difference-between-enabled-isactiveandenabled-and-activeinhierarchy-in-unity
2023.05.11 15:01 -
[Unity] 현재 실행중인 애니메이터의 길이를 구하는 방법 GetCurrentAnimatorStateInfo
현재 실행 중인 애니메이터의 길이를 얻으려면 Animator 컴포넌트의 GetCurrentAnimatorStateInfo 메서드를 사용하여 현재 상태 정보를 가져와야 합니다. 이 메서드는 현재 애니메이터 상태에 대한 정보를 반환합니다. 다음은 C# 코드의 예입니다. Animator animator = GetComponent(); AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); float length = stateInfo.length; 이 코드에서 animator 변수는 현재 게임 오브젝트에서 Animator 컴포넌트를 가져오기 위해 사용되고, GetCurrentAnimatorStateInfo 메서드는 현재 애니메이터 상태에 대..
2023.02.22 14:53