์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•
Project Euler is the site where you can find various mathematical problems
which are mostly able to be solved by using programming tools like C++, java and the other
language unlike UVA(ACM-ICPC) Problems.

 You can improve your mathematical ability as well as coding skills.
Thus, I recommend you to visit "http://www.projectEuler.net" and have a nice time
solving tons of problems. :)

The below is the code which I already solved NO.32 which is relatively easier than the
latter numbers of problems.(it may harm your creativity to see below)
 
:)

 ํ”„๋กœ์ ํŠธ ์˜ค์ผ๋Ÿฌ๋Š” C์™€ Java ๊ฐ™์€ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํˆด๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š” ์ˆ˜ํ•™์ ์ธ ๋ฌธ์ œ๋“ค์ด ๋งŽ์€ ์‚ฌ์ดํŠธ ์ž…๋‹ˆ๋‹ค.
UVA๋ฌธ์ œ๋“ค๊ณผ๋Š” ๋‹ฌ๋ฆฌ ์ˆ˜ํ•™์ ์ธ ๋ถ€๋ถ„์— ์ข€ ๋” ํฌ์ปค์Šค๋ฅผ ๋’€์œผ๋ฉฐ, ๊ฐ์ข… ์Šคํฌ๋ฆฝํŠธ ์–ธ์–ด๋„ ํ—ˆ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 ์ฝ”๋”ฉ ์Šคํ‚ฌ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ˆ˜ํ•™์ ์ธ ๋Šฅ๋ ฅ์„ ๊ธฐ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ http://www.ProjectEuler.net์—
ํ•œ๋ฒˆ ๊ฐ€๋ณด์‹œ๊ธธ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค :)

 ์•„๋ž˜๋Š” ์ œ๊ฐ€ ์ตœ๊ทผ์— ํ‘ผ ๋น„๊ต์  ์‰ฌ์šด 32๋ฒˆ ๋ฌธ์ œ์˜ ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค. (์Šคํฌ์ผ๋Ÿฌ์„ฑ)
 
#include
 <cstdio>
#include <iostream>
#include <string>
#include <set>
//#include <vector>
//#include <algorithm>

using namespace std;


set< int > setInteger;

string intToString(int nInput);

//string ํ˜•์„ ๋ฐ›์•„์„œ panDigit์ด ๋˜์—ˆ๋Š”์ง€ ์•„๋‹Œ์ง€ ํ™•์ธ
bool isPanDigit(string x, string y, string strResult);
int main()
{

  int i,j;


  //์ •๋‹ต ์ €์žฅ
  int nResult = 0;


  for( i = 1 ; i <= 100 ;i++ )
  {
    for( j = 1 ; j <= 10000 ;j++ )
    {
      
      // i  j   i*j
      if(isPanDigit(intToString(i),  intToString(j),  intToString(i*j) ) )
      {
        cout << "panDigit ๋ฐœ๊ฒฌ : " << i << " X " << j << = " << i*j << endl;
        
        setInteger.insert(i*j);
      }
    }

  }

  //for(i = 0 ; i < setInteger.size() ; i++)
  for( set< int > :: iterator it = setInteger.begin() ; it != setInteger.end() ;it++ )
  {
    nResult += (*it);
  }
  cout << "์ค‘๋ณต์š”์†Œ ์ œ๊ฑฐํ•œ ์ •๋‹ต : " << nResult << endl;




  return 0;
}




//int -> string
string intToString(int nInput)
{
  // int ๋ฅผ string ์œผ๋กœ ๋ฐ”๊พธ๊ธฐ ์‹œ์ž‘

  char    szBuf[512];
  sprintf(szBuf,"%d",nInput);
  string    strTemp(szBuf);

  return strTemp;
  // int ๋ฅผ string ์œผ๋กœ ๋ฐ”๊พธ๊ธฐ ๋.
}


//string ํ˜•์„ ๋ฐ›์•„์„œ panDigit์ด ๋˜์—ˆ๋Š”์ง€ ์•„๋‹Œ์ง€ ํ™•์ธ
bool isPanDigit(string x, string y, string strResult)
{
  int i;

  bool bPanDigit[10= {false};

  // ex) X * Y = result ์ผ๋•Œ X์˜ ๋ฌธ์ž๊ธธ์ด ๋งŒํผ ๊ตฌํ•œํ›„..
  for(i = 0 ; i < x.size() ; i++)
  {
    if(bPanDigit[   x[i]-'0'  ]== true)
    {
      return false;
    }
    bPanDigit[   x[i]-'0'  ] = true
  }
  for(i = 0 ; i < y.size() ; i++)
  {
    if(bPanDigit[   y[i]-'0'  ]== true)
    {
      return false;
    }
    bPanDigit[   y[i]-'0'  ] = true
  }
  for(i = 0 ; i < strResult.size() ; i++)
  {
    if(bPanDigit[   strResult[i]-'0'  ]== true)
    {
      return false;
    }
    bPanDigit[   strResult[i]-'0'  ] = true
  }


  //๋ชจ๋“  ๋ฐฐ์—ด์ด true์ด๋ฉด true ํ•˜๋‚˜๋ผ๋„ false ์ด๋ฉด false
  if(bPanDigit[0== true)
  {
    return false;
  }
  for(i = 1 ; i < 10 ; i++)
  {
    if( bPanDigit[i] == false )
    {
      return false;
    }
  }

  return true;
  //
}
๋ฐ˜์‘ํ˜•

+ Recent posts