/*3 * 3 배열로 된 테트리스 모양 회전시키기
 *스페이스바를 누르면, 90도씩 회전하는 로직*/

class Program
{
    public static void Main()
    {
        TrisCls nm = new TrisCls();
        nm.running();
    }
}
class TrisCls
{
    //desinition & variables
    const int ARR=3;
    int[,] design = new int[,]
    {
        {0,0,1},
        {1,1,1}, 
        {0,0,1}
    }
    //control
    ConsoleKeyInfo keyinfo;

    public void running()
    {
        int rc;
        while(true)
        {
            keyinfo=Console.ReadKey(true);
            if(keyinfo.Key==ConsoleKey.Escape) break;
            if(keyinfo.Key==ConsoleKey.Spacebar) 
            {
                rc=design_rotation();
                rc=design_rotation();
            }

            draw();
        }
    }
    int design_rotation()
    {
        int tmp;

        tmp = design[0,0];
        design[0,0]=design[0,1];
        design[0,1]=design[0,2];
        design[0,2]=design[1,2];
        design[1,2]=design[2,2];
        design[2,2]=design[2,1];
        design[2,1]=design[2,0];
        design[2,0]=design[1,0];
        design[1,0]=tmp;

        return(1);
    }
    void draw()
    {
        string text="";
        int ii,kk;

        for(ii=0; ii<ARR; ii++)
        {
            for(kk=0; kk<ARR; kk++)
            {
                if(design[ii,kk]==1) text=text+"U";
                else text=text+"_";
            }
            text=text+"\n";
        }
        Console.Write(text);
    }
}



        

#솔류션 + 프로젝트 다수일경우 참조방법

하나의 솔류션에 여러개의 프로젝트 단위로 나누어서 프로그램을 구성하는경우에
DLL파일 참조시에, 프로젝트 단위별로 DLL참조를 해야한다.

프로젝트(1) -> 속성(R) -> 참조경로(1)

프로젝트(1) -> 속성(R) -> 참조경로(2) ex>C:\Program Files\ComponetOne\Studio for WinForms\bin\v4\

위의 이미지에서, 참조경로에 추가를 해주면 됩니다.

C1 배포 & Deploy

컴포넌트원(ComponentOne)를 배포하는 방법에 대한 설명입니다.

배포가 될 때 사용중인 아래의 DLL이 같이 배포된 프로그램의 같은 경로에 포함되어야 합니다.

  • C1.Win.2.dll
  • C1.Win.컨트롤 이름.2.dll/C1.C1 컨트롤 이름.2.dll
  • C1.Win.4.dll
  • C1.Win. 컨트롤 이름.4.dll/C1.C1 컨트롤 이름.4.dll
  • C1.Win. 컨트롤 이름.4.Design.dll/C1.C1 컨트롤 이름.4.Design.dll

DLL에 붙어 있는 숫자 2와 4는 기본적으로 .NET 프레임 워크와 호환성을 나타내며 해당 DLL이 다양한 타입의 호환성을 가지기 때문에 현재는 문제가 되지 않더라도 장래적인 호환성을 위하여 배포하실 때는 2가지 버전의 DLL을 모두 배포하여야 합니다.

예를 들어 C1.Win.FlexGrid.2.dll와 C1.Win.FlexGrid.4.dll을 모두 배포하여야 합니다.

C1.C1Excel.4.5.2 Assembly / C1.C1Excel Namespace

 

C1.C1Excel Namespace | ComponentOne Excel for .NET

 

www.grapecity.com




Class                    Description

  C1XLBook Represents an Excel workbook containing one or more worksheets.
Contains methods for loading and saving XLS files, and exposes a collection of XLSheet objects that represent the individual worksheets.
  ShapeCollection Represents a collection of XLShape objects on an XLSheet.
  Strings Static class containing UI strings used by the designer.
  XLBorderFormatting The border formatting.
  XLCell Represents individual cells in an XLSheet and provides properties for getting and setting the cell Value, Style, and Hyperlink.
  XLCellRange Represents a range of XLCell objects in an XLSheet.
  XLCellRangeCollection Represents a collection of XLCellRange objects on an XLSheet.
  XLColumn Represents a column in a worksheet. This class provides properties for setting the column's width, style, and visibility.

/*

31 characters

Microsoft Excel does not allow worksheet name longer than 31 characters.

*/

/*

Excel Worksheet Naming Rules and Tips
► A worksheet name cannot cannot exceed 31 characters. ► A worksheet name cannot be left blank. ► A worksheet cannot be named history in either lower or uppercase.

*/

 

using C1.C1Excel;

 

namespace Problem

{

    class Program

    {

        public static void Main(string[] args)

        {

            Problem_2021_10_15 nm = new Problem_2021_10_15();

            nm.running();

        }

    }

    class Problem_2021_10_15

    {

        public void running()

        {

            C1XLBook book = new C1XLBook();

            XLSheet sheet = book.Sheets[0];

            sheet.Name="1234567890123456789012345678901";
            //Microsoft Excel does not allow worksheet name longer than 31 characters.

            XLStyle style = new XLStyle();

            style.AlignHorz = XLAlignHorzEnum.Center;

            XLCell cell = sheet[1,0];

            cell.Value="1234567890123456789012345678901";
            //Microsoft Excel does not allow worksheet name longer than 31 characters.

        }

    }

}

/*
 * C# Excel 연동(엑셀 COM 레퍼런스 추가하기)
 */

엑셀 COM 레퍼런스 추가하기

1. 개체추가
일단 C# 에서 엑셀 연동을 하기 위하여는 참조 개체를 추가해야 합니다.
상단 메뉴의 "프로젝트" -> "참조" 로 이동하신 다음 아래와 같은 항목을 찾아서 체크해 줍니다.

앞쪽의 체크박스를 선택해주고 확인 버튼을 눌러주면 된다.

2. 선언
확인을 누르셨으면 이제 해당 레퍼런스를 사용하도록 선언을 해줍니다.

코드 페이지의 제일 윗 부분에 아래와 같이 작성을 해 주겠습니다.

using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using Application = Microsoft.Office.Interop.Excel.Application;

두번째 추가한 구문은 현재 열려있는 엑셀 어플리케이션을 확인하기 위한 용도로 사용합니다.

세번쨰 구문은 이후 사용할 Application 이라는 지시어가 현재 C# 컴파일러가 헷깔릴수 있는 용어이기 때문에 특별히 어떤 녀석인지를 지시하도록 작성하였습니다.

3. 코드작성
이제 사용할 준비는 되었고 코드를 작성해 보겠습니다.

아래와 같이 작성이 되면 됩니다. 본인의 비주얼 스튜디오에 복붙 하지 마시고 한번 타이핑 해보시기 바랍니다. 코딩의 재미중에 타이핑 하는 맛도 빼 놓을 수 없기 때문이며 직접 타이핑을 해보는게 좀더 빠르게 익숙해 지기 때문이기도 하죠. 물론 인텔리센스가 도와주기 때문에 사실 몇글자 씩만 적어도 아래에 적어야 될 코드들이 자동으로 나타나서 저처럼 영문 타이핑을 못하는 사람도 쉽게 코딩을 할 수 있습니다.

한번 코드를 보실까요? 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using Application = Microsoft.Office.Interop.Excel.Application;

namespace excelAutomate
{
    public partial class Form1 : Form
    {
        private Application xlsApp;


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 폼 로딩시에 위에서 정의한 xls App 를 엑셀과 연동해 주겠습니다.
            xlsApp = (Application)Marshal.GetActiveObject("Excel.Application"); // 현재  열려있는 엑셀 어플리케이션이 지정됩니다.
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 버튼을 누르면 텍스트 박스에 엑셀 어플리케이션이 열고 있는 엑셀 파일 명을 표시해 보겠습니다.
            textBox1.Text = xlsApp.ActiveWorkbook.Name;
        }
    }
}

 

 

문제 1

문제 풀이 : Lv1. 숫자 문자열과 영단어

  • 1478 → “one4seveneight”
  • 234567 → “23four5six7”
  • 10203 → “1zerotwozero3”

네오와 프로도가 위와 같이 숫자를 문자열로 바꾸는 게임을 하고 있습니다. 이때 일부 자릿수가 영단어로 바뀌었거나 바뀌지 않고 그대로인 문자열 s가 매개변수로 주어질 때, s가 의미하는 원래 숫자를 return 하는 함수를 완성해 주세요.

제한사항

  • 1 ≤ s의 길이 ≤ 50
  • s가 “zero” 또는 “0”으로 시작하는 경우는 주어지지 않습니다.
  • return 값이 1 이상 2,000,000,000 이하의 정수가 되는 올바른 입력만 s로 주어집니다.

입출력 예

"one4seveneight" 1478
"23four5six7" 234567
"2three45sixseven" 234567
"123" 123

 

 

 

using System;
using System.IO;
using System.Timers;

namespace ProblemPackage
{
    class Program
    {
        public static void Main(string[] args)
        {
            Tris_2021_10_15 nm = new Tris_2021_10_15();

            if(args.Length == 1)
            {
                nm.running(args[0]);
            }
            else
            {
                nm.running("23four5six7");
                nm.running("one4seveneight");
            }
        }
    }
    class Tris_2021_10_15
    {
        string[] english = new string[]
        {
            "zero",
            "one",
            "two",
            "three",
            "four",
            "five",
            "six",
            "seven",
            "eight",
            "nine"
        };
        string[] numeric = new string[]
        {
            "0",
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9"
        };
        const int TRUE=1;
        const int FAIL=0;

        public void running(string text)
        {
            string[] result = new string[100];
            string tmp;
            int kk,ii,ff;

            Console.WriteLine("Problem String------------------------------------------------");
            Console.WriteLine("[" + text + "]");

            kk=0;
            ii=0;
            while(true)
            {
                if(search_string(text)==TRUE)
                {
                    result[kk]=get_string(text);

                    ff=text.Length-result[kk].Length;
                    tmp = text.Substring(result[kk].Length,ff);
                    text="";
                    text=tmp;
                    kk++;
                }
                else
                {
                    result[kk]=get_number(text);

                    ff=text.Length-1;
                    tmp = text.Substring(1,ff);
                    text="";
                    text=tmp;
                    kk++;
                }

                ii++;
                if(text=="") break;
            }

            tmp="";
            for(kk=0; kk<ii; kk++)
            {
                if(result[kk].Length > 1) 
                {
                    for(ff=0; ff<10; ff++)
                    {
                        if(result[kk].CompareTo(english[ff])==0)
                        {
                            tmp = tmp + numeric[ff];
                            break;
                        }
                    }
                }
                else tmp = tmp + result[kk];
            }

            Console.WriteLine("Result String------------------------------------------------");
            Console.WriteLine("[" + tmp + "]");
        }
        int search_string(string str)
        {
            int kk,ii,ff;

            for(kk=0; kk<str.Length; kk++)
            {
                ii = (str.Substring(kk,1)).CompareTo("a");
                ff = (str.Substring(kk,1)).CompareTo("z");

                if(ii==0) return TRUE;
                if(ff==0) return TRUE;

                if(ii == 1 && ff == -1)
                {
                    return TRUE;
                }

                ii = (str.Substring(kk,1)).CompareTo("0");
                ff = (str.Substring(kk,1)).CompareTo("9");

                if(ii==0) return FAIL;
                if(ff==0) return FAIL;

                if(ii == 1 && ff == -1)
                {
                    return FAIL;
                }
            }
            return -1;
        }
        string get_number(string str)
        {
            return(str.Substring(0,1));
        }
        string get_string(string str)
        {
            int ii,kk;
            int max,min;
            string min_final_str;
            string max_final_str;

            max=-999;
            min=999;

            min_final_str="";
            max_final_str="";
            for(kk=0; kk<10; kk++)
            {
                ii = str.IndexOf(english[kk]);

                if(ii < 0) continue;

                if(max < ii)
                {
                    max=ii;
                    max_final_str = str.Substring(ii,english[kk].Length);
                }
                if(min > ii)
                {
                    min=ii;
                    min_final_str = str.Substring(ii,english[kk].Length);
                }
            }
            return(min_final_str);
        }
    }//end of class
}//end of nameapace

/*console 3*3 tris game source
 *cmd>type *.cs | findstr formattext
*/

using System;
using System.IO;
using System.Timers;

namespace ____java_is_package
{
    class Program
    {
        public static void Main(string[] args)
        {
            ____tris_overloading_cls nm = new ____tris_overloading_cls();
            nm.running();
        }
    }

    class ____tris_overloading_cls
    {
        //properties
        const int TRUE=1;
        const int FAIL=0;
        const int D_RIGHT=1000;
        const int D_LEFT=1001;
        const int D_DOWN=1002;
        const int MAPY=22;
        const int MAPX=22;
        const int ARR=3;
        const int MAXDESIGN=10;

        int xpos,ypos,hyun_design,next_design;
        int[,] tris=new int[MAPY,MAPX];
        int[,] design=new int[ARR,ARR];
        int[,,] realdesign=new int[,,]
        {
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
            {{1,1,1},{1,1,1},{1,1,1}},
        };

        Timer tm;

        //method
        void draw_tris()
        {
            string formattext="";
            string spacetext="                                          ";
            int ii,kk;

            for(ii=0; ii<MAPY-1; ii++)
            {
                formattext=formattext+spacetext;
                for(kk=1; kk<MAPX-1; kk++)
                {
                    if(tris[ii,kk]==1) formattext=formattext+"U";
                    else formattext=formattext+"_";
                 }
                 formattext=formattext+"\n";
             }
             Console.SetCursorPosition(0,0);
             Console.Write(formattext);
        }

        int common_check(int direction)
        {
            int[,] tris_tmp=new int[MAPY,MAPX];
            int ii,kk,ff;

            for(ALL)for(ALL)tris_tmp[ii,kk]=tris[ii,kk];
            for(ARR)for(ARR)if(design[ii,kk]==1) tris_tmp[ypos+ii,xpos+kk]=0;

            if(direction==D_RIGHT) xpos++;
            if(xpos+2>MAX-1) xpos--; //Array's MAX-1 Access Possible

            if(direction==D_LEFT) xpos--;
            if(xpos+0<0) xpos++ //Array's 0 Access Possible

            if(direction==D_DOWN) ypos++;

            for(ARR)for(ARR)if(design[ii,kk]==1) tris_tmp[ypos+ii,xpos+kk]=1;

            ff=0;
            for(ARR)for(ARR)if(tris_tmp[ypos+ii,xpos+kk]>1) ff++;

            if(ff > 0) 
            {if(direction==D_RIGHT) xpos--;
            if(direction==D_LEFT) xpos++;
            if(direction==D_DOWN) ypos--; return(FAIL)}
            else
            {
                for(ALL)for(ALL)tris[ii,kk]=tris_tmp[ii,kk];}
            }
            return(TRUE);
        }     
        void init()
        {
            int ii,kk;

            tm=new Timer();
            tm.Elapsed += new ElapsedEventHandler(____time_tick);
            tm.Interval=500;
            tm.Start();

            for(ALL)for(ALL)tris[ii,kk]=0;
            for(ii=0; ii<MAPY; ii++) tris[ii,0]=1; tris[ii,MAPX-1]=1;
            for(kk=0; kk<MAPX; kk++) tris[MAPY-1,kk]=1;

            xpos=MAPX/2; ypos=0; score=0;
            Random rr=new Random(); hyun_design=rr.Next() % MAXDESIGN; next_design=rr.Next() % MAXDESIGN;

            for(ARR)for(ARR) design[ii,kk]=realdesign[hyun_design,ii,kk];
            for(ARR)for(ARR) tris[ypos+ii,xpos+kk]=design[ii,kk];

            Console.Clear(); draw_tris();
        }
        int enter_check()
        {
            int ii,kk,rc;

            while(true)
            {
                rc=common_check(D_DOWN);
                if(rc==FAIL) break;

                draw_tris();
            }
            while(true)
            {
                if(check_horizon()==FAIL) break;
            }
            xpos=MAPX/2; ypos=0;
            hyun_design=next_design;
            Random rr=new Random(); next_design=rr.Next() % MAXDESIGN;
            for(ARR)for(ARR) design=realdesign[hyun_design];
            for(ARR)for(ARR) tris[ypos+ii,xpos+kk]=design[ii,kk];
            draw_tris();
            return(TRUE);
        }
        void ____time_check(object sender, ElapsedEventArgs e)
        {
            int ii,kk,rc;

            draw_tris();
            rc=common_check(D_DOWN);
            if(rc==FAIL)
            {
                if(ypos==0) stop();
                else
                {
                    while(true)
                    {
                        //no detect!!, while loop break!!
                        //no detect!!, while loop break!!
                        if(check_horizon()==FAIL) break;
                    }
                }
                xpos=MAPX/2; ypos=0;
                hyun_design=next_design;
                Random rr=new Random(); next_design=rr.Next() % MAXDESIGN;
                for(ARR)for(ARR) design[ii,kk]=realdesign[hyun_design,ii,kk];
                for(ARR)for(ARR) tris[ypos+ii,xpos+kk]=design[ii,kk];
            }
        }
        public void running()
        {
            int rc; ConsoleKeyInfo keyinfo;
            init();
            while(true)
            {
                keyinfo=Console.ReadKey(true);
                if(keyinfo.Key==ConsoleKey.RightArrow) rc=common_check(D_RIGHT);
                if(keyinfo.Key==ConsoleKey.LEFTArrow) rc=common_check(D_LEFT);
                if(keyinfo.Key==ConsoleKey.Escape) break;
                if(keyinfo.Key==ConsoleKey.Enter) rc=enter_check();
                draw_tris();
            }
            stop();
        }
        void draw_tris()
        {
            int ii,kk;
            string formattext="";

            for(ii=0; ii<MAPY-1; ii++)
            {
                for(kk=1; kk<MAPX-1; kk++)
                {
                    if(tris[ii,kk]==1) formattext=formattext+"U";
                    else formattext=formattext+"_";
                }
                formattext=formattext+"\n";
            }
            Console.SetCursorPosition(0,0);
            Console.Write(formattext);
        }
        void delete_column(int x, int y)
        {
            int ii;

            for(ii=y; ii>=1; ii--)
            {
                tris[ii.x]=tris[ii-1,x];
            }
        }
        int check_horizon()
        {
            int ii,kk,idx,horizon;

            horizon=MAPX-3;
            for(ii=0; ii<MAPY-1; ii++)
            {
                idx=0;
                for(kk=1; kk<MAPX-2; kk++)
                {
                    if(tris[ii,kk]==tris[ii,kk+1]) idx++;
                    else break;
                }
                if(idx==horizon)
                {
                    for(kk=1; kk<MAPX-1; kk++) delete_column(ii,kk);
                    score++;
                    return(TRUE);
                }
            }
            return(FAIL);
        }
    }//end of class
}

 

+ Recent posts