Coding/CPP 삽질기2007. 9. 17. 01:45
// 흐미... 심심해서 해본게 생각보다 시간을 많이 까먹었다.
// TDD는 정말 중요하다.

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
void process(void);
int main(void)
{
    process();  
    return 0;
}

void process(void)
{
     string alpha = "0123456789";
     int synap = 0;
     int soft = 0;
     int wants = 0;
     int you = 0;
     int result = 0;
     int count = 0;
    
     //'SYNAP + SOFT = WANTS + YOU'
     // 0123456789
     // AFNOPSTUWY
     
     do
     {
           
        if (alpha[5] == '0' || alpha[8] == '0' || alpha[9] == '0')
            continue;
       
        synap = (alpha[5]-'0')*10000 + (alpha[9]-'0')*1000 + (alpha[2]-'0')*100 + (alpha[0]-'0')*10 + (alpha[4]-'0');            
        soft = (alpha[5]-'0')*1000 + (alpha[3]-'0')*100 + (alpha[1]-'0')*10 + (alpha[6]-'0');
        wants = (alpha[8]-'0')*10000 + (alpha[0]-'0')*1000 + (alpha[2]-'0')*100 + (alpha[6]-'0')*10 + (alpha[5]-'0');            
        you = (alpha[9]-'0')*100 + (alpha[3]-'0')*10 + (alpha[7]-'0');
       
        if (synap + soft == wants + you)           
        {
            cout << synap << " + " << soft << " = " << wants << " + " << you << endl;     
            result += wants + you;
            cout << result << endl;
        }
       
     } while (next_permutation(alpha.begin(), alpha.end())  );
    
}

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

연산자 우선 순위  (0) 2008.01.13
비트 연산자  (0) 2007.04.24
별 그려주는 코드  (0) 2006.08.22
Posted by chobocho