C#/C#언어

0318 _ 다차원 연습 문제 1 _ 10개

minquu 2021. 3. 18. 16:45
반응형

1.

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {200, 200, 200},
                {100, 100, 200},
                {100, 100, 100},
                {100, 100, 100}
            };
            Console.WriteLine("****************************************");
            Console.WriteLine("{0}", arr.GetLength(0)); //row
            Console.WriteLine("{0}", arr.GetLength(1)); //col
            Console.WriteLine("****************************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0, 2}", arr[i, j]);
                }
                Console.WriteLine(" ");
                Console.WriteLine(" ");
            }

        }
    }

}

------------

2.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {100, 100, 100},
                {100, 100, 301},
                {100, 303, 302},
            };
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("****************************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write("  {0, 2}", arr[i, j]);
                }
                Console.WriteLine();
                Console.WriteLine();
            }
        }

    }

}

 

-----

3.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {100, 308, 307},
                {200, 200, 100},
                {303, 305, 200},
                {304, 306, 100},
            };

            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("***************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine(" ");
                Console.WriteLine(" ");
            }
        }
    }
}

 

----

4.

 

 

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {309, 306, 100, 100},
                {200, 200, 100, 200},
            };

            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("*****************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine(" ");
                Console.WriteLine(" ");
            }
        }
    }
}

 

-----

5.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {309, 306, 100, 100},
                {200, 200, 100, 200},
            };

            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("***********************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine(" ");
                Console.WriteLine(" ");
            }

        }
    }
}

 

----

6.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {100, 100, 100, 100, 100},
                {312, 312, 305, 100, 100}
            };

            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("*******************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine("");
            }

        }
    }
}

 

 

----

7.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {312, 305, 100 },
                {313, 311, 310 },
                {309, 306, 100 },
                {200, 200, 100 },
                {100, 200, 200 },
            };
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("*******************");

            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine(" ");
            }
        }
    }
}

 

----

 

8.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {200, 200, 200, 100, 100},
                {100, 303, 305, 200, 200},
                {308, 304, 311, 100, 200},
            };
            Console.WriteLine("*************************");
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("*************************");
            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine(" ");
                Console.WriteLine(" ");
            }
        }
    }
}

 

----

9. 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {100, 100, 200, 200 },
                {100, 200, 200, 200 },
                {200, 100, 100, 100 },
                {100, 100, 100, 100 }
            };
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("************************");

            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine(" ");
            }
        }
    }
}

 

--

10. 캐릭터 위치

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study08
{
    class App
    {
        public App()
        {
            //배열 선언 및 초기화
            int[,] arr = {
                {100, 100, 200, 200 },
                {100, 200, 200, 200 },
                {200, 100, 100, 100 },
                {100, 100, 100, 100 }
            };
            Console.WriteLine("************* MAP **********");
            Console.WriteLine("{0}", arr.GetLength(0));
            Console.WriteLine("{0}", arr.GetLength(1));
            Console.WriteLine("************* MAP **********");

            for (int i = 0; i < arr.GetLength(0); i++) {
                for (int j = 0; j < arr.GetLength(1); j++) {
                    Console.Write(" {0}", arr[i, j]);
                }
                Console.WriteLine(" ");
            }

            int[,] heroArr;
            heroArr = new int[4, 4];
            Console.WriteLine("************* HERO **********");
            heroArr[2, 1] = 1;
            Console.WriteLine("{0}",heroArr.GetLength(0));
            Console.WriteLine("{0}", heroArr.GetLength(1));
            Console.WriteLine("************* HERO **********");
            for (int i = 0; i < heroArr.GetLength(0); i++) {
                for (int j = 0; j < heroArr.GetLength(1); j++) {
                    Console.Write(" {0}", heroArr[i, j]);
                }
                Console.WriteLine(" ");
            }
        }
    }
}

 

반응형