'Coding/CPP 삽질기'에 해당되는 글 45건

  1. 2014.10.24 대칭행렬
  2. 2014.03.28 Programming 실습 예제
  3. 2013.06.06 피보나치 수열
  4. 2013.05.24 함수 실행 시간 측정
  5. 2013.05.13 fall-through
  6. 2012.10.25 Programming quiz
  7. 2011.09.08 Unity3D (1)
  8. 2011.04.04 static int box[1000] = {1, };
  9. 2011.02.06 간단한(?) 퀴즈 2
  10. 2010.01.28 [CPP] 파일 분할 프로그램 v0.01
Coding/CPP 삽질기2014. 10. 24. 01:49

#include <iostream>

using namespace std;


int main (int argc, char **argv) {

    

    int i = 0;

    int j = 0;

    

    for ( i = 0; i < 7; i++ ) {

        for ( j = 0; j < 7; j++ ) {

            cout << int(i^j) << " ";

        }

        cout << endl;

    }

    

    return 0;

}



Hi-iMac:CPP chobocho$ ./matrix.o 

0 1 2 3 4 5 6 

1 0 3 2 5 4 7 

2 3 0 1 6 7 4 

3 2 1 0 7 6 5 

4 5 6 7 0 1 2 

5 4 7 6 1 0 3 

6 7 4 5 2 3 0 

'Coding > CPP 삽질기' 카테고리의 다른 글

Mirror  (0) 2014.10.27
Programming 실습 예제  (0) 2014.03.28
피보나치 수열  (0) 2013.06.06
Posted by chobocho
Coding/CPP 삽질기2014. 3. 28. 04:02

 Programming 실습 예제


[ 기초 ]

1. Array 기반의 스택

2. Array 기반의 큐

3. Array 기반의 환형 큐

4. Double Linked List

5. Linked list를 이용한 스택

6. Linked list를 이용한 큐

7. Array 한 개로, 스택과 큐를 동시에 쓸수 있게 하기


'Coding > CPP 삽질기' 카테고리의 다른 글

대칭행렬  (0) 2014.10.24
피보나치 수열  (0) 2013.06.06
함수 실행 시간 측정  (0) 2013.05.24
Posted by chobocho
Coding/CPP 삽질기2013. 6. 6. 22:46

동적알고리즘을 이용한 피보나치 수열 


int arrFibonacci[100000] = { 0, };


int fibonacci ( int number ) {

    int ret = 0;

    

    if ( number <= 0 ) {

        ret = -1;

    }

    else if ( number == 1 || number == 2  ) {

          ret = 1;    

    } else {

    if ( arrFibonacci[number] == 0 ) { 

            arrFibonacci[number] = fibonacci(number-1) + fibonacci(number-2);  

         }

         ret = arrFibonacci[number];

    }

    

    return ret;

}


'Coding > CPP 삽질기' 카테고리의 다른 글

Programming 실습 예제  (0) 2014.03.28
함수 실행 시간 측정  (0) 2013.05.24
fall-through  (0) 2013.05.13
Posted by chobocho
Coding/CPP 삽질기2013. 5. 24. 01:13

#include <ctime>

using namespace std;

void ellaspedTimeTest() { clock_t start_time; clock_t end_time; start_time = clock();


//Do something ...

end_time = clock(); ellasped_time = (double)(end_time - start_time)/CLOCKS_PER_SEC;

}

'Coding > CPP 삽질기' 카테고리의 다른 글

피보나치 수열  (0) 2013.06.06
fall-through  (0) 2013.05.13
Programming quiz  (0) 2012.10.25
Posted by chobocho
Coding/CPP 삽질기2013. 5. 13. 23:29

switch ( number ) {

    case 1:

         cout << "My "; 

         /* fall through */

    case 2:

         cout << "name ";

         /* fall through */

    case 3:

         cout << "is ";

         /* fall through */

    case 4:

         cout << "H.";

         break;

    default:

          cout << endl;

}

'Coding > CPP 삽질기' 카테고리의 다른 글

함수 실행 시간 측정  (0) 2013.05.24
Programming quiz  (0) 2012.10.25
Unity3D (1)  (0) 2011.09.08
Posted by chobocho
Coding/CPP 삽질기2012. 10. 25. 01:08

1. 중복되지 않은 임의의 100개의 점이 있다. 100개의 점을 모두 연결 하여 닫힌 다각형이 되도록 점을 배열 하여라.

    예) (10, 10), (100, 1), ( 200, 300 ), ( 550 , 2) ... ( x, y ) ==> ( 10, 10 ),  ( 100, 1 ), ( 550, 2 ), ( 200, 300 )

    입력값 예)

    입력값 수

    입력 값 { x, y  | x > 0 && y > 0  }

   

   [ Input.txt ]

   4

  10  10

  100  1

  200 300

  550 2


   [ Data file ]

http://www.chobocho.com/wiki/moniwiki/wiki.php?10000%EA%B0%9C%EC%A2%8C%ED%91%9C%EC%83%9D%EC%84%B1&action=UploadedFiles&dummy=1

2. 중복되지 않은 임의의 100개의 점이 있다. 100개의 점을 모두 둘러싸는 경계에 포함 되는 점을 순서대로 배열 하여라.

    예) (10, 10), (100, 1), ( 200, 300 ), (100, 2),  ( 550 , 2) ... ( x, y ) ==> ( 10, 10 ),  ( 100, 1 ), ( 550, 2 ), ( 200, 300 )

    입력값 예)

    입력값 수

    입력 값 { x, y | x > 0 && y > 0 }

   

  [ Input.txt ]

  5

  10  10

  100  1

  100  2  

  200 300

  550 2




3. 임의의 두개의 삼각형이 있다. 겹치는 부분의 넓이를 구하여라.
[ Input.txt ]
10 10
20 20
30 30
15 15
20 20
30 30

4. 중복되지 않은 임의의 10000개의 점이 있다. 10000개의 점들 중 가장 가까운 두개의 점의 좌표를 구하여라.

    예) (10, 10), (10, 11), ( 200, 300 ), (100, 2),  ( 550 , 2) ... ( x, y ) ==> ( 10, 10 ),  ( 10, 11 )

    입력값 예)

    입력값 수

    입력 값 { x, y | x > 0 && y > 0 }

   

  [ Input.txt ]

  5

  10  10

  10  11

  100  2  

  200 300

  550 2


    [ Data file ]

http://www.chobocho.com/wiki/moniwiki/wiki.php?10000%EA%B0%9C%EC%A2%8C%ED%91%9C%EC%83%9D%EC%84%B1&action=UploadedFiles&dummy=1


'Coding > CPP 삽질기' 카테고리의 다른 글

fall-through  (0) 2013.05.13
Unity3D (1)  (0) 2011.09.08
static int box[1000] = {1, };  (0) 2011.04.04
Posted by chobocho
Coding/CPP 삽질기2011. 9. 8. 00:42
1. Unity3D down 받기
 
http://unity3d.com/unity/download/


2. 실행화면


 
 

'Coding > CPP 삽질기' 카테고리의 다른 글

Programming quiz  (0) 2012.10.25
static int box[1000] = {1, };  (0) 2011.04.04
간단한(?) 퀴즈  (2) 2011.02.06
Posted by chobocho
Coding/CPP 삽질기2011. 4. 4. 17:37


static int box[1000];

static int box[1000] = {0, };

static int box[1000] = {1, };


의 차이는?

 
static int box[1000] = {1, }; 의 경우

컴파일시 바이너리의 크기가 sizeof(int) * 1000 만큼 커진다. 

'Coding > CPP 삽질기' 카테고리의 다른 글

Unity3D (1)  (0) 2011.09.08
간단한(?) 퀴즈  (2) 2011.02.06
[CPP] 파일 분할 프로그램 v0.01  (0) 2010.01.28
Posted by chobocho
Coding/CPP 삽질기2011. 2. 6. 01:09
1. Thread와 Process의 차이는?

2. Compiler와 Interpreter의 차이는?

3. C로 binary tree를 짜보시오.

4. C에서 Stack과 Heap의 구조에 대해서 설명하시오.

5. 자바에서 Garbage collection에 대해서 설명 하시오.

6. BNF란?

7. C로 Quick sort를 구현해 보시오.

8. Quick sort의 Big(O)는 얼마인가?

9. Unix에서 IPC의 방법을 설명하시오.

  


'Coding > CPP 삽질기' 카테고리의 다른 글

static int box[1000] = {1, };  (0) 2011.04.04
[CPP] 파일 분할 프로그램 v0.01  (0) 2010.01.28
[CPP] Lotto 생성기  (0) 2010.01.22
Posted by chobocho
Coding/CPP 삽질기2010. 1. 28. 00:18

//============================================================================
// Name        : ChoboSplit.cpp
// Author      : chobocho.com
// Version     : v0.011
// CopyLeft
// Description : File Split
// Date        : 2010. 10. 28
//============================================================================

#include <iostream>
#include <fstream>
using namespace std;

#define _10MB (10*1024*1024)

class CSplit {
public:
    CSplit();
    ~CSplit();
    bool split(char *fileName);
    void make_batch_file (char *fileName, int count);
private:
    fstream source_fp;
    fstream target_fp;
};

CSplit::CSplit()
{

}

CSplit::~CSplit()
{
    source_fp.close();
    target_fp.close();
}


bool CSplit::split(char *fileName)
{
    int nof_target = 0;
    int count = 0;
    int read_size = 8192;
    char buffer[8192];

    string target_filename = fileName;
    target_filename += ".sh";

    source_fp.open(fileName, ios::binary|ios::in);
    target_fp.open(target_filename.c_str(), ios::binary|ios::out|ios::trunc);
    if (!source_fp)
    {
       cout << "Error : Can't find " << fileName << " !!" << endl;
       return false;
    }

    source_fp.seekg(0, ios_base::end);
    long source_filesize = source_fp.tellg();

    cout << "source file size : " << source_filesize << endl;

     // 10MB 이하의 파일은 분할 할 필요가 없음
    if ( source_filesize <= _10MB )
    {
         cout << "No need to split!" << endl;
         source_fp.close();
         return false;
     }

     source_fp.seekg(ios_base::beg);

     if (!target_fp)
    {
        cout << "Error : Can't open target file !!" << endl;
        return false;
    }

    while(( !source_fp.eof() )&& (source_filesize > 0) )
    {
        memset(buffer, 0, 8192);

        if (source_filesize < read_size)
        {
            read_size = source_filesize;
         }

         source_fp.read( buffer, read_size );
         target_fp.write( buffer, read_size );
         count += read_size;
         source_filesize -= read_size;

        if (count >= _10MB)
        {
            count = 0;
            target_fp.close();
            cout << "Make " << nof_target+1 << " file!" <<endl;
            char next_target_filename[256];
            sprintf( next_target_filename, "%s.s%d", fileName, nof_target++ );
            target_fp.open(next_target_filename, ios::binary|ios::out|ios::trunc);
            if (!target_fp)
            {
                source_fp.close();
                cout << "Error : Can't open target file !!" << endl;
                return false;
             }
        }
    }

    source_fp.close();
    target_fp.close();

    make_batch_file (fileName, nof_target);

    return true;
}

void CSplit::make_batch_file (char *fileName, int count)
{
    int i = 0;

    ofstream target("run.bat", ios::out);
    target << "echo off" << endl;

    target << "if not exist "<< fileName <<".sh goto error" << endl;
    for (i = 0; i < count ; i++)
    {
         target << "if not exist " << fileName << ".s" << i << " goto error" << i << endl;
    }

    target << "copy /b "<< fileName <<".sh";
    for (i = 0; i < count ; i++)
    {
     target << " + " << fileName << ".s" << i;
    }
    target << " " << fileName << endl;
    target << "goto finish" << endl;

    target << ":error" << endl;
    target << "echo Error : " << fileName << ".sh not exist" << endl;
    target << "goto finish" << endl;

    for (i = 0; i < count; i++)
    {
        target << ":error" << i << endl;
        target << "echo Error : " << fileName <<".s" << i << " not exist" << endl;
        target << "goto finish" << endl;
    }
    target << ":finish" << endl;
    target << "echo Finish" <<endl;
    target.close();
}

int main(int argc, char **argv) {
    cout << "!!!Chobo Spilt V0.011!!!" << endl;

    CSplit mySplit;

    if (argc >= 2)
   {
       mySplit.split(argv[1]);
    }
    cout << "!!!End!!!" <<endl;
    return 0;
}



실행결과

생성파일 : Run.bat + 분할된 파일들

Run.bat 의 내용
echo off
if not exist test.zip.sh goto error
if not exist test.zip.s0 goto error0
if not exist test.zip.s1 goto error1
if not exist test.zip.s2 goto error2
if not exist test.zip.s3 goto error3
if not exist test.zip.s4 goto error4
copy /b test.zip.sh + test.zip.s0 + test.zip.s1 + test.zip.s2 + test.zip.s3 + test.zip.s4 test.zip
goto finish
:error
echo Error : test.zip.sh not exist
goto finish
:error0
echo Error : test.zip.s0 not exist
goto finish
:error1
echo Error : test.zip.s1 not exist
goto finish
:error2
echo Error : test.zip.s2 not exist
goto finish
:error3
echo Error : test.zip.s3 not exist
goto finish
:error4
echo Error : test.zip.s4 not exist
goto finish
:finish
echo Finish



'Coding > CPP 삽질기' 카테고리의 다른 글

간단한(?) 퀴즈  (2) 2011.02.06
[CPP] Lotto 생성기  (0) 2010.01.22
[CPP] 폴더내 파일 목록을 보여 주는 코드 조각  (1) 2009.03.24
Posted by chobocho