'2009/09/15'에 해당되는 글 4건

  1. 2009.09.15 [C#] Collections (2)
  2. 2009.09.15 SRM 150 DIV 2 (250)
  3. 2009.09.15 SRM 149 DIV 2 (250)
  4. 2009.09.15 2학년 2학기 시간표 1

[C#] Collections (2)

Programming/.NET Programming 2009. 9. 15. 23:15

Collections 용어 정리

      Collection : 데이터 보관 가능 수정, 삭제 삽입의 기능을 가지고 있음
      ex. *(원형)Linked List, *Stack, *Queue, *List, Array List, Hash, Hash Table 등

      1. Linked List : 노드와 노드 간이 포인터로 연결되어 있어서 노드 간 검색이 가능

      2. Array List :  List와 거의 흡사, List와 구분이 되는 것은 자료형을 따지지 않는 점.
                        노드간의 다른 자료형을 넣을 수 있음. 편하지만 용량을 많이 차지.

      3. List : 사용법은 1차원 배열과 같음,
                Stack, Queue, Linked List의 모든 단점을 보완할 수 있음,
                노드간 검색 가능하고 Stack, Queue의 모든 기능을 소화함.
                넣을 때 insert, 뺄 때 remove
                원하는 인덱스에 넣고 뺄 수 있음(Stack, Queue 대신 이걸 더 많이 씀)

      4. Stack : 넣을 때 push, 뺄 때 pop, LIFO

      5. Queue : 넣을 때 enqueue, 뺄 때 dequeue, FIFO 

      6. Hash : 넓은 범위의 것을 좁게 접근, 인덱스를 가지고 있음.
                  각각 node에 key값과 value값을 가짐.
                  value에 접근할 때 key로 접근이 가능함

      - 배열과 Collection의 가장 큰 차이점 : 정적 - 동적의 차이

 

Stack 예제

using System;

using System.Collections; // Stack을 사용하기 위해 필요한 namespace

using System.Collections.Generic; // Stack을 사용하기 위해 필요한 namespace

namespace Stack

{

class Program

    {

static void Main(string[] args)

        {

            Stack<int> stackTest = new Stack<int>(); // Stack 생성

 

            for (int i = 0; i < 10; i++)

                stackTest.Push(i); // Data 입력

 

            while (stackTest.Count != 0)

                Console.WriteLine(stackTest.Pop()); // Data 출력

        }

    }

} 

 

 

Queue 예제

using System;

using System.Collections; // Queue을 사용하기 위해 필요한 namespace

using System.Collections.Generic; // Queue을 사용하기 위해 필요한 namespace

namespace Queue

{

class Program

    {

        static void Main(string[] args)

        {

            Queue<int> queueTest = new Queue<int>(); // Queue 생성

 

            for (int i = 0; i < 10; i++)

                queueTest.Enqueue(i); // Data 입력

 

            while (queueTest.Count != 0)

                Console.WriteLine(queueTest.Dequeue()); // Data 출력

        }

    }

} 

  

 

Hach Table 예제

using System;

using System.Collections; // Hach Table을 사용하기 위해 필요한 namespace

 

namespace HachTable

{

class Program

    {

        static void Main(string[] args)

        {

            Hashtable table = new Hashtable();

            table.Add("Happy", "^^*");

            table.Add("Sad", "T_T");

            table.Add(0, 5);

            Console.WriteLine(table["Happy"]);

 

            A a = new A();

            Object b = new A();

 

            // 명시되어 있지는 않지만 모든 클래스는 object클래스로 부터 상속 받음.

            // 가장 기본적인 클래스이기 때문.

            // class A는 사용자가 method를 입력하지 않았지만 몇가지 method를 기본적으로 가지고 있음.

            // table.Add(Object Key, Object Value)에는 아무 자료형(class, string, int ...)이나 들어가도 됨

            // Object가 가장 기본이 되는 클래스이기 때문임

        }

    }

    class A { }

}

 

  

 


'Programming > .NET Programming' 카테고리의 다른 글

[C#] Collections (3)  (0) 2009.06.02
[C#] Collections (1)  (0) 2009.06.02
[C#] Enum과 배열  (0) 2009.05.31
[C#] this와 상속  (0) 2009.05.31
[C#] 오버로딩과 오버라이딩  (0) 2009.05.31
:

SRM 150 DIV 2 (250)

Programming/SRM Practice 2009. 9. 15. 23:11
SRM 150 DIV 2 (250)
문제 요약 : 지갑을 고치는 데 몇 일을 소비할까?

using System;

 

public class WidgetRepairs

{

    public int days(int[] arrivals, int numPerDay)

    {

        int days = 0;

        int remains = 0;

 

        for (int i = 0; i < arrivals.Length - 1; i++)

        {

            arrivals[i] += remains;

            remains = 0;

 

            if (arrivals[i] == 0) continue;

 

            if (arrivals[i] - numPerDay > 0)

            {

                int temp = arrivals[i] - numPerDay;

 

                if (temp > numPerDay)  remains = temp;

                else arrivals[i + 1] += temp;

            }

            days++;

        }

        days += (arrivals[arrivals.Length - 1] + remains) / numPerDay;

        if ((arrivals[arrivals.Length - 1] + remains) % numPerDay != 0) days++;

        return days;

    }

}


'Programming > SRM Practice' 카테고리의 다른 글

SRM 149 DIV 2 (250)  (0) 2009.09.15
SRM 307 DIV 2 (250)  (0) 2009.07.04
SRM 191 DIV 2 (250)  (0) 2009.05.30
SRM 148 DIV 2 (250)  (0) 2009.05.27
SRM 146 DIV 2 (250)  (0) 2009.05.27
:

SRM 149 DIV 2 (250)

Programming/SRM Practice 2009. 9. 15. 23:04
SRM 149 DIV 2 (250)
문제 요약 : dollars, cents 표기법에 맞게 출력하기

using System;

 

public class FormatAmt

{

    public string amount(int dollars, int cents)

    {

        string res = "", temp = dollars.ToString();

        for (int i = temp.Length - 1; i >= 0; i--)

        {

            res = temp[i] + res;

            if ((temp.Length - i) % 3 == 0 && i != 0) res = "," + res;

        }

        if (cents.ToString().Length > 1) res += "." + cents.ToString();

        else res += ".0" + cents.ToString();

        return "$" + res;

    }

}


'Programming > SRM Practice' 카테고리의 다른 글

SRM 150 DIV 2 (250)  (0) 2009.09.15
SRM 307 DIV 2 (250)  (0) 2009.07.04
SRM 191 DIV 2 (250)  (0) 2009.05.30
SRM 148 DIV 2 (250)  (0) 2009.05.27
SRM 146 DIV 2 (250)  (0) 2009.05.27
:

2학년 2학기 시간표

Scribbling 2009. 9. 15. 22:59


이번학기는 이메진컵 준비, 창의과제하려고

오후로 수업 몰아서 뭔가 널널하게 살려고 했는데..


17학점 같지 않은 17학점이라니.. 매우 바쁘다.

'Scribbling' 카테고리의 다른 글

100명에게 아이폰을 쏜다!  (0) 2010.01.04
또 일내다.  (0) 2009.09.24
: