Blog Content

  • 15.C# - 알고리즘 : LINQ 그룹 (LINQ - Group)

    Category C# on 2009. 8. 20. 00:27

    C# LINQ를 이용한 그룹 알고리즘 예제입니다. Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Collections; public class ProductInfo { public string Name { get; set; } public int Quantity { get; set; } } public class 그룹알고리즘 { public static void Main() { //[1]Input List lst = new List() { new ProductInfo{Name="RADIO", Quantity=3}, new ProductInfo{Name="TV", Quantity=1}, ne..

    Read more
  • 14.C# -알고리즘 : LINQ 병합 (LINQ - MEARGE)

    Category C# on 2009. 8. 20. 00:14

    C# LINQ를 이용한 배열 병합 예제입니다. Program.cs using System; using System.Linq; public class 병합 { public static void Main() { int[] data1 = { 3, 5, 4 }; int[] data2 = { 2, 1 }; int[] result = (from o in data1 select o).Union( from t in data2 select t).OrderBy(x => x).ToArray(); for (int i = 0; i < result.Length; i++) { Console.WriteLine("{0}",result[i]); } } } 결과화면

    Read more
  • 13.C# - 알고리즘 : 그룹

    Category C# on 2009. 8. 18. 21:22

    group 절은 그룹의 키 값과 일치하는 하나 이상의 항목을 포함하는 IGrouping (TKey, TElement)개체 시퀀스를 반환합니다. 예를 들어 각 문자열의 첫 글자에 따라 문자열 시퀀스를 그룹화할 수 있습니다. 이 경우 첫 글자가 키가 되고 키의 형식은 char이며 각 IGrouping)개체의 Key 속성에 저장됩니다. 컴파일러가 키의 형식을 유추합니다. [출처-멍멍,MSDN] Program.cs using System; using System.Collections.Generic; public class ProductInfo { public string Name { get; set; } // 상품명 public int Quantity { get; set; } // 판매량 public Produ..

    Read more
  • 12.C# - 알고리즘 : 병합 (MEARGE)

    Category C# on 2009. 8. 12. 22:36

    정수형 값이 저장된 두개의 배열을 더하여 하나로 묶은 다음 배열안에 있는 정수형 값을 작은 숫자 부터 큰 숫자까지 나타내는 예제 입니다. MEARGE.cs using System; public class MEARGE { public static void Main() { //[1] Input : 원본 데이터가 정렬되어있다고 가정 int[] first = { 1, 3, 5 }; int[] second = { 2, 4 }; //Mearge될 배열 int[] mearge = new int[first.Length + second.Length]; //병합정렬코드 int i = 0; int j = 0; int k = 0; int M = first.Length; int N = second.Length; //[2] Pr..

    Read more
  • 11.C# - 알고리즘 : 카운터 (Count)

    Category C# on 2009. 8. 12. 22:02

    배열에 저장된 값중에 짝수인 정수를 찾는 예제로 배열에 저장된 값중에서 짝수인 정수가 총 몇개인지 구하는 예제입니다. 여기서 사용된 키워드는 Count입니다. Count는 증가한다는 뜻으로 사용됩니다. Count.cs using System; public class 카운트 { public static void Main(string[] args) { //[1] Input int[] data = { 10, 9, 4, 7, 6, 5 }; int count = 0; //카운트 저장 //[2] Process : COUNT for (int i=0; i < data.Length; i++) { if (data[i] % 2 == 0) { count ++; //카운트 증가 } } //[3] Output Console.Wr..

    Read more
  • 10.C# - 알고리즘 : 검색 (Serch)

    Category C# on 2009. 8. 12. 21:33

    배열에 저장된 값들 중에서 사용자가 입력한 값이 저장된 배열에 몇번째 위치에 있는지를 찾는 예제 입니다. 예제1에서는 순차적인 앞에서 부터 차례대로 검색하는 방법이고, 두번째 예제2는 사용자가 입력한 값을 가지고 중간 배열부터 찾는 예제 입니다. 속도면에서는 예제2가 빠릅니다. Serch.cs using System; public class 이진검색 { public static void Main() { //[1] Input int[] data = { 1, 3, 5, 7, 9 }; Console.WriteLine("찾을 데이터 : "); int search = Convert.ToInt32(Console.ReadLine()); bool flag = false; //찾았으면 true 그렇지않으면 false i..

    Read more
  • 09.C# - 알고리즘 : 정렬(Sort)

    Category C# on 2009. 8. 7. 21:31

    정렬(Sort)-순서대로 정렬시키는 알고리즘으로 오름차순과 내림차순이 있습니다. 오름차순(Ascending)정렬 : 1,2,3 ABC순 내림차순(Desending)정렬 : 3,2,1 다나가 순 종류로는 : 선택정렬, 버블정렬, 퀵정렬, 삽입, 기수등이 있습니다. using System; public class 선택정렬 { public static void Main() { //[1] Input int[] data = { 7, 5, 6 }; //[2] Process int temp = 0; for (int i = 0; i data[j]) { temp = dat..

    Read more
  • 08.C# - 알고리즘 : 순위 Rank

    Category C# on 2009. 8. 7. 21:13

    주어진 범위 안에서 순위를 구하는 알고리즘입니다. 순위 배열을 1등으로 값을 초기화 한 후 초기값 보다 큰 값이 나오면 1씩 증가시켜서 결과값을 구하는 예제 입니다. http://blog.naver.com/min9888596 [멍멍님 블로그] using System; public class 순위 { public static void Main(string[] args) { //[1] Input int[] score = { 90, 87, 100, 95, 80, 34 }; int[] rank = { 1, 1, 1, 1, 1, 1 }; //[2] Process for (int i = 0; i < score.Length; i++) { for (int j = 0; j < score.Length; j++) { //비..

    Read more
  • 07.C# - 알고리즘 : 수열 구하기

    Category C# on 2009. 8. 6. 21:37

    예제1 : 1 - 2 + 3 - 4 + 5 ... +99 - 100 = ? 구하기 using System; public class 간단수열 { public static void Main(string[] args) { int total = 0; for (int i = 1; i

    Read more
이전 1 다음