ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2020-04-21[문제(예제) 1/2/3/4] / 3번 못품
    카테고리 없음 2020. 4. 22. 02:18

    문제 1 

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    using System;
    using System.Collections.Generic;
    using System.Linq;
     
    namespace ConsoleApp4
    {
        class App
        {
            public App()
            {
                List<int> list = new List<int>();
                list.Add(1);
                list.Add(2);
                list.Add(3);
                int sum = this.GetSumFromList(list);
                Console.WriteLine(sum); //6
            }
            public int GetSumFromList(List<int> list)
            {
                int result = 0;
                foreach (int num in list)
                {
                    result += i;
                }
                return result;
            }
     
        }
    }
     
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

     

     

     

    문제2 

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Pratice010
    {
        public class Item
        {
            public string name;
            public Item(string name)
            {
                this.name = name;
            }
        }
        class APP
        {
            public APP()
            {
                Item item = this.CreateItem("장검");
                Console.WriteLine(item.name);    //장검
            }
     
            public Item CreateItem(string name)
            {
                return new Item(name);
            }
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

    문제 4

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Pratice010
    {
        class ItemData
        {
            public string name;
            public int amount;
            public ItemData(string name, int amount)
            {
                this.name = name;
                this.amount = amount;
            }
        }
        class APP
        {
            List<ItemData> ItemDatasList;
            List<string> itemNameList;
            List<int> itemAmountList;
            public APP()
            {
                itemNameList = new List<string>();
     
                itemNameList.Add("김밥");
                itemNameList.Add("순대");
     
                itemAmountList = new List<int>();
     
                itemAmountList.Add(3);
                itemAmountList.Add(4);
     
                ItemDatasList = this.AdditemDataList(itemNameList, itemAmountList);
     
                foreach (ItemData element in ItemDatasList)
                {
                    Console.WriteLine("{0}X{1}"element.name, element.amount);   //김밥X3 순대X4
                }
            }
     
            public List<ItemData> AdditemDataList(List<string> NameList, List<int> AmountList)
            {
                List<ItemData> Datalist = new List<ItemData>();
     
                for (int i = 0; i<NameList.Count; i++)
                {
                    ItemData data = new ItemData(NameList[i], AmountList[i]);
                    Datalist.Add(data);
     
                }
     
                return Datalist;
            }
     
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

    문제3 역순으로 할 생각이 안떠오르고 검색시  Array.Reverse가 나오나 활용할수가 없음 

Designed by Tistory.