[C#] SortedSet 중복 없는 배열 생성
·
언어/C#
백준 25192번 문제를 풀면서 사용한 SortedSet은 중복 없는 배열을 알아서 만들어줍니다. using System; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int i, num = 0; string enter = null; SortedSet s = new SortedSet(); enter = Console.ReadLine(); for (i = 0; i < n-1; i++) { enter = Console.ReadLine(); if (enter == "ENTER") { num += s.Count(); s.Clear(); } else { s.Add(enter); } } num += s..
[게임 서버] Server와 Client의 통신, 패킷(Packet) 정보 주고 받기
·
공부/게임 서버
Server에서 Client로, 또는 반대의 상황에서 정보를 주고 받는 방법을 살펴보자. Packet을 상속받는 정보들이 있다. Packet에는 모든 아이들이 반드시 가져야 할 기본 정보인 size와 packetId, Write()와 Read()를 지니고 있다. public abstract class Packet { public ushort size; public ushort packetId; public abstract ArraySegment Write(); public abstract void Read(ArraySegment s); } size는 말 그대로 정보의 크기다. packetId는 패킷을 구분해줄 장치다. Write는 패킷을 보낼 때 사용하고 Read는 패킷을 받을 때 사용한다. Player..
[C#] 백준 10989번 : StreamReader
·
언어/C#
using System; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] arr = new int[10001]; for (int i = 0; i < N; i++) arr[int.Parse(Console.ReadLine())]++; for (int i = 0; i < 10000; i++) { if (arr[i] != 0) { for (int j = 0; j < arr[i]; j++) Console.WriteLine(i); } } } } 메모리를 아끼기 위해 2751번에서 사용했던 Array.Sort 방식이 아니라 다른 방식을 사용해야 했다. 구글링을 통해서 필요한 최대 크기의 배열을 미..
[C#] 백준 1929번 : 에라토스테네스의 체 방식(빠르게 소수 찾기)
·
언어/C#
using System; using System.Text; class Program { static void Main(string[] args) { StringBuilder sb = new StringBuilder(); string[] s = Console.ReadLine().Split(); int M = int.Parse(s[0]); int N = int.Parse(s[1]); bool OK = true; if (M == 1) M++; for (int i = M; i < N; i++) { OK = true; for (int j = 2; j
[C#] 백준 2581번
·
언어/C#
using System; class Program { static void Main(string[] args) { int M = int.Parse(Console.ReadLine()); int N = int.Parse(Console.ReadLine()); int min = 0; int sum = 0; bool[] arr = new bool[N + 1]; bool ok = false; for (int i = M; i
[C#] 백준 10757번 : 큰 수를 다룰 땐 BigInteger를 활용하자
·
언어/C#
백준 10757번문제다. int, long으로는 답을 구할 수 없다. 이땐 BigInteger로 변수를 지정해주면 큰 수를 다룰 수 있다.👍 using System; using System.Net.Http.Headers; using System.Numerics; using System.Text; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(); BigInteger a = BigInteger.Parse(s[0]); BigInteger b = BigInteger.Parse(s[1]); Console.WriteLine(a + b); } }
[C#] 백준 2839번
·
언어/C#
using System; using System.Net.Http.Headers; class Program { static void Main(string[] args) { /* 1. N이 5의 배수 * 2. N이 3의 배수 * 3. N을 5로 나눴는데 나머지가 3의 배수 * 4. N을 3으로 나눴는데 나머지가 5의 배수 */ int N = int.Parse(Console.ReadLine()); int count = 0; while (N > 0) { if (N % 5 == 0) { N -= 5; count++; } else if (N % 3 == 0) { N -= 3; count++; } else if (N > 5) { N -= 5; count++; } else { count = -1; break; } } ..
[C#] 백준 2292번
·
언어/C#
using System; class Program { static void Main(string[] args) { int S = int.Parse(Console.ReadLine()); int N = 1; int i = 1; if (S == 1) Console.WriteLine(1); else { while (true) { N += 6 * i; if (S
[C#] 백준 1712번
·
언어/C#
using System; class Program { static void Main(string[] args) { string[] arr = Console.ReadLine().Split(); int A = int.Parse(arr[0]); int B = int.Parse(arr[1]); int C = int.Parse(arr[2]); int x = 1; if (B >= C) Console.WriteLine(-1); else { Console.WriteLine(A / (C - B) + 1); } } } 손익분기점이 존재하지 않는 부분은 가변비용(B)이 판매비용(C)와 같거나 높은 경우다. 판매비용(x)를 구하는 단순한 식을 통해 x를 구하고 출력한다.
[C#] StringBuilder란
·
언어/C#
string a = "안녕"; string b = "Hi"; Console.WriteLine(a + b); 기존 string을 사용하여 문자열을 합치면 a와 b각각의 instance가 생성되는 낭비가 발생한다. StringBuilder sum = new StringBuilder(); sum.Append("안녕"); sum.Append("Hi"); Console.WriteLine(sum.ToString()); StringBuilder를 사용하면 새로운 변수가 생성될 필요 없이 값을 추가할 수 있어서 낭비가 없다. 아주 적은 양의 문자열을 사용할 경우는 상관 없지만 많은 양을 사용할 경우 StringBuilder를 사용해야 한다.
[EFCore] Eager Loading / Explicit Loading / Select Loading
·
공부/EFCore
✅ Eager Loading public static void EagerLoading() { Console.WriteLine("길드 이름을 입력하세요"); Console.Write("> "); string name = Console.ReadLine(); using (var db = new AppDbContext()) { Guild guild = db.Guilds.AsNoTracking() .Where(g => g.GuildName == name) .Include(g => g.Members) .ThenInclude(p => p.Item) .First(); foreach (Player player in guild.Members) { Console.WriteLine($"TemplateId({player.Ite..
[EFCore] Include VS ThenInclude
·
공부/EFCore
[Table("Item")] public class Item { // 이름Id -> PK public int ItemId { get; set; } public int TemplateId { get; set; } // 101 = 집행검 public DateTime CreateDate { get; set; } // 다른 클래스 참조 -> FK (Navigational Property) [ForeignKey("OwnerId")] public Player Owner { get; set; } } [Table("Player")] // Entity 클래스 이름 = 테이블 이름 = Player public class Player { // 이름Id -> PK public int PlayerId { get; set; } ..
[EFCore] System.TypeInitializationException과 Unable to load 'sni.dll' 오류해결하기
·
공부/EFCore
1. 자세히 보기를 눌러 코드를 하나하나 훑으면서 오류 찾아서 해결하기 2. NuGet 패키지 관리자에서 System.Data.SqlClient 최신 버전 설치하기 3. NuGet 패키지 관리자에서 Microsoft.Data.SqlClient 최신 버전 설치하기 난 여기서 해결됐다.
[C#] 구조체(struct)란?
·
언어/C#
구조체(struct)란 데이터 관련 기능을 캡슐화해놓는 형식이다. https://codingjin0424.tistory.com/18 [C] 구조체 - 고양이 뽑기 게임 #include #include #include typedef struct { char* name; int age; char* character; int level; } CAT; int collection[5] = { 0,0,0,0,0 }; CAT cats[5]; void initCats(); void printCat(int collect); int c.. codingjin0424.tistory.com 예전에 했던 고양이 뽑기 게임처럼 내가 원하는 고양이의 정보를 모아놓은 구조체를 통해 고양이 정보를 사용할 수 있다.
[게임 서버] SetBuffer를 RecvBuffer, SendBuffer로 따로 빼내기 #2
·
공부/게임 서버
지난 게시글에서는 RecvBuffer를 만들었다. 이번에는 SendBuffer를 만들어 따로 빼내보겠다. SendBuffer는 크게 두 클래스로 나뉜다. SendBufferHelper와 SendBuffer다. SendBufferHelper 먼저 살펴보자. // ThreadLocal == 전역은 전역 변순데 내 스레드에서만 사용할 수 있는 전역변수 public static ThreadLocal CurrentBuffer = new ThreadLocal(() => { return null; }); // 그냥 사이즈가 아니라 되게 큰 뭉탱이 Size. 여기서 필요한 만큼 뽑아다 쓸 예정. public static int ChunkSize { get; set; } = 4096 * 100; 멀티 스레드 환경에서도 ..