#pragma warning(disable: 4786)
#include "stdafx.h"
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std ;
//-------------------------------------------------------------------
const int VECTOR_SIZE = 6 ;
// Define a template class vector of strings
typedef vector<string> StrVector ;
//Define an iterator for template class vector of strings
typedef StrVector::iterator StrVectorIt ;
//Define an ostream iterator for strings
typedef ostream_iterator<string> StrOstreamIt;
//-------------------------------------------------------------------
void PrintQuestion(StrVectorIt it, StrVectorIt start, StrVectorIt end)
{
for ( it = start; it != end; it++ )
{
if ( it == start )
{
cout << *it ;
}
else
{
cout << "+" << *it ;
}
}
printf("\t");
}
string GetResultValue1(StrVectorIt it, StrVectorIt start, StrVectorIt end)
{
string strBuffer;
for ( it = start; it != end; it++ )
{
strBuffer += *it;
}
cout << strBuffer << "\t";
return strBuffer;
}
void TranslateToValue2(string strResultValue1)
{
int n; // 탐색중인 문자열 위치
int nResultLength; // 탐색중인 문자열의 총 길이
int k = 1; // 같은 문자열의 길이(3기준)의 오버된 갯수
char szResult[20] = {0}; // 결과값2
char szTemp[20] = {0}; // 결과값1
strcpy( szTemp, strResultValue1.c_str() );
nResultLength = (int)strlen(szTemp);
for ( n = 0; n < nResultLength; n++ )
{
szResult[n] = szTemp[n];
if ( '0' == szTemp[n] && '0' == szTemp[n+1] && '0' == szTemp[n+2] )
{
while( '0' == szTemp[n+2+k] )
{
k++;
}
szResult[n+1] = '\0';
strcat(szResult, szTemp+n+2+k);
strcpy(szTemp, szResult);
nResultLength = nResultLength - 1 - k; // 총 문자열의 길이 재설정
n = -1;
k = 1;
}
else if( '1' == szTemp[n] && '1' == szTemp[n+1] && '1' == szTemp[n+2] )
{
while ( '1' == szTemp[n+2+k] )
{
k++;
}
szResult[n] = '0';
szResult[n+1] = '\0';
strcat(szResult, szTemp+n+2+k);
strcpy(szTemp, szResult);
nResultLength = nResultLength - 1 - k; // 총 문자열의 길이 재설정
n = -1;
k = 1;
}
}
printf("%s\n", szResult); // 결과값2 출력
}
int main()
{
StrVector Pattern(VECTOR_SIZE) ;
StrVectorIt start, end, it ;
start = Pattern.begin() ; // location of first
// element of Pattern
end = Pattern.end() ; // one past the location last
// element of Pattern
//Initialize vector Pattern
Pattern[0] = "001" ;
Pattern[1] = "010" ;
Pattern[2] = "011" ;
Pattern[3] = "100" ;
Pattern[4] = "101" ;
Pattern[5] = "110" ;
printf("\t문자열\t\t\t결과값1\t\t\t결과값2\n");
string strResultValue1;
int count = 1;
do
{
count++;
if(count%250 == 0)
{
printf("다음결과를 보시려면 Enter를 입력하여 주십시오");
scanf("%[^\n]");
}
PrintQuestion(it, start, end); // 문자열 출력
strResultValue1.clear();
strResultValue1 = GetResultValue1(it, start, end); // 순열에 정렬된 결과값1 문자열 출력
TranslateToValue2(strResultValue1); // 결과값1을 결과값2로 변환 및 출력
}
while ( next_permutation(start, end) ); // STL 순열함수
fflush(stdin);
printf("끝내시려면 Enter를 입력하여 주십시오");
scanf("%[^\n]");
return 0;
}
'Programming' 카테고리의 다른 글
| rand(), srand(), RAND_MAX (0) | 2007/11/10 |
|---|---|
| 맵핑이란.. Mapping (0) | 2007/10/05 |
| ID3DXSprite::Begin (0) | 2007/10/02 |
| D3DXCreateSprite (0) | 2007/09/30 |
| 연결 리스트 ( Linked List ) 링크드 리스트 (0) | 2007/09/23 |
| 순열(next_permutation)과 문자열 변환 (0) | 2007/09/16 |
| next_permutation (0) | 2007/09/13 |
| DICamera (0) | 2007/06/19 |
| Camera Class 구현 (0) | 2007/06/19 |
| DirectX Study (3) (0) | 2007/06/19 |
| DirectX Study (2) (0) | 2007/06/18 |






댓글을 달아 주세요