목록C++ & C# (31)
오보에블로그
Comparision 정렬 메소드중 오버로드 된것중에 하나로는 List.Sort(Comparision) 가 있다. Comparision 는 delegate 로 정의된 대리자로, delegate int Comparison(T x, T y); 로 Comparison에는 x 와 y를 받아서 x가 y 보다 작으면 0보다 작은 정수를, x 와 y가 같으면 0을, x가 y 보다 크면 1 을 리턴해야하는 함수를 할당해야한다. 이걸 쓰면 크고 작음의 기준을 커스텀하게 작성할 수 있어서 편리하다. 예시 public string[] solution(string[] strings, int n) { List stringList = new List(); stringList.AddRange(strings); stringList...
Count Count(IEnumerable, Func) 해당 람다식에서 true를 반환하는 원소만 센다. 예시 List numbers = new List() {1,2,3,4,5,6,7,8}; int answer = numbers.Count( x => { if (x % 2 == 1) return true; else return false; } ); Select 해당 열거자에대해 다른 포맷으로 변경 예시 int[] numbers = {1,2,3,4,5,6,7 }; IEnumerable query = numbers.Select((number, index) => { if (number % 2 == 0) return number; else return -1; }); IEnumerable squares = Enum..
IEnumerator와 IEnumerable 사용 목적은 아래 링크를 참고한다. IEnmerator 인터페이스 설명 public interface IEnumerator { // Enumerator의 열거자에서 현재 바라보고 있는 위치를 반환 object? Current { get; } // 열거자에서 다음 element로 이동하는 함수 bool MoveNext(); // 열거자에서 현재 바라보고 있는 위치를 초기로 변환 void Reset(); } IEnumerable 인터페이스 설명 public interface IEnumerable { // 열거자에 대한 Enumerator 반환 IEnumerator GetEnumerator(); } IEnumerator , IEnumerable 이용 예시 class..
API 링크 참고 StirngBuilder string 에 짧은 시간동안 이어 붙이면 동적할당이 빈번하게 일어나서 성능이 저하 될 수 있다. StringBuilder은 변경 가능한 문자열 class이다. 사용 예시 static StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(result[i] + 1 + " ");
https://social.msdn.microsoft.com/Forums/vstudio/en-US/8c5c792f-d17d-443c-8098-76797aafd588/algorithm-the-longest-common-substring-of-two-strings?forum=csharpgeneral Algorithm the longest common substring of two strings Well, if you want a good algorithm, you can find it in Wikipedia: https://en.wikipedia.org/wiki/Longest_common_substring_problem The algorithm there is written in pseudo-code, bu..
try , catch 구문에서 try에 다른 프로그램을 실행시킬때, error를 catch 하지 못할때가 있습니다. (설령 catch 한다고 하더라도 프로그램이 끝난후에야 catch 될 때) 그럴 때는 비동기 thread인 task를 이용하고 아주 멋지신 분이 정리 해놓은 코드를 사용하도록 합시다. https://pastebin.com/K8MWQuJ6 [C#] Task with timeout - Pastebin.com Not a member of Pastebin yet? Sign Up, it unlocks many cool features! class Program { static void Main(string[] args) { var program = new Program(); program.Test(..
A Simple Linux Shell 본 설계 프로젝트에서는 간단한 리눅스 명령어 해석기(일명: smsh)를 스스로 만들어 본다. 설계 및 구현해야 할 smsh는 다음과 같은 명령어를 처리할 수 있어야 한다. foreground and background execution (&) multiple commands separated by semicolons history command shell redirection (>, >>, >|, 0 && strcmp(buffer[buf_leng-1],">")== 0){ strcat(buffer[buf_leng-1],">"); } else{ if(strcmp(buffer[buf_leng],"") != 0) buf_leng++; strcat(buffer[buf_leng..
전투 드로이드 가격 성공 한국어원문 문제집 시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율 1 초 128 MB 1751 1064 1001 62.916% 문제 상근이는 망가진 전투 드로이드를 고치려고 하고 있다. 전투 드로이드의 각 부품의 가격은 다음과 같다. 블래스터 라이플 $350.34 시각 센서 $230.90 청각 센서 $190.55 팔 $125.30 다리 $180.90 입력 첫째 줄에 테스트 케이스의 개수가 주어진다. 각 테스트 케이스는 음이 아닌 정수 다섯 개(A B C D E)로 이루어져 있다. A: 필요한 블래스터 라이플의 개수 B: 필요한 시각 센서의 개수 C: 필요한 청각 센서의 개수 D: 필요한 팔의 수 E: 필요한 다리의 수 출력 각 테스트 케이스 마다, 입력으로 주어진 부품을 ..
/* 별 찍기 - 17 시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율 1 초 256 MB 2221 1540 1448 71.506% 문제 예제를 보고 별찍는 규칙을 유추한 뒤에 별을 찍어 보세요. 입력 첫째 줄에 N (10) printf(" "); for(int j = i-2; j>=0;j--){ printf(" "); } printf("*"); for(int j = 2*(N-i)-1; j > 0 ; j--){ printf(" "); } if(i