Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341231
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:07:54

#include
#include
using namespace std;

unsigned long getRadix(int n)
{
unsigned long lRadix = 1;
while(--n)
{
lRadix = lRadix * 10;
}
return lRadix;
}

bool VerifyNumber(unsigned long m, int n)
{
unsigned int nLength = 0;
char buffer[15];
_itoa_s(m, buffer, 15, 10);
nLength = (unsigned int)strlen(buffer);

if (nLength != n)
return false;

bool bRs = true;

while(nLength>1)
{
if (nLength == 2)
{
if (m%100/10 <= m%10)
{
bRs = false;
break;
}
}
else
{
int i, j;
i = m/getRadix(nLength);
j = (m-m/getRadix(nLength)*getRadix(nLength))/getRadix(nLength-1);
if (i <= j)
{
bRs = false;
break;
}
}

m -= m/getRadix(nLength)*getRadix(nLength);
nLength--;
}

return bRs;
}

void fun(int m, int n)
{
unsigned long lMax = 0;
lMax = m;
int i = n;
while(i>1)
{
lMax += m * getRadix(i) ;
i--;
}

cout << "The Max number is : " << lMax <
while(lMax)
{
if(VerifyNumber(lMax, n))
cout << lMax << "  ";

lMax--;
}

}

int main(void)
{
fun(9,4);

cin.get();

return 0;
}

--------------------next---------------------

阅读(1172) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~