用c语言编写花朵数程序,C语言写的21位花朵数

// 21位花朵数.cpp : 定义控制台应用程序的入口点。

//

#include "stdafx.h"

#include

#define N 21

using namespace std;

void fang(int x);

int arr[10][21];

int main()

{

int cot[10];

for(int i = 0;i < 10; ++i)

{

cot[i] = 0;

fang(i);

}

//生成一个N位数并计数该数中每个数字出现的次数

for(cot[9] = 0;cot[9] <= 9; ++cot[9])

{

for(cot[8] = 0;cot[8] <= N - cot[9]; ++cot[8])

{

for(cot[7] = 0;cot[7] <= N - cot[9] - cot[8]; ++cot[7])

{

for(cot[6] = 0;cot[6] <= N - cot[9] - cot[8] - cot[7]; ++cot[6])

{

for(cot[5] = 0;cot[5] <= N - cot[9] - cot[8] - cot[7] - cot[6]; ++cot[5])

{

for(cot[4] = 0;cot[4] <= N - cot[9] - cot[8] - cot[7] - cot[6] - cot[5]; ++cot[4])

{

for(cot[3] = 0;cot[3] <= N - cot[9] - cot[8] - cot[7] - cot[6] - cot[5] - cot[4]; ++cot[3])

{

for(cot[2] = 0;cot[2] <= N - cot[9] - cot[8] - cot[7] - cot[6] - cot[5] - cot[4] - cot[3]; ++cot[2])

{

for(cot[1] = 0;cot[1] <= N - cot[9] - cot[8] - cot[7] - cot[6] - cot[5] - cot[4] - cot[3] - cot[2]; ++cot[1])

{

cot[0] = N - cot[9] - cot[8] - cot[7] - cot[6] - cot[5] - cot[4] - cot[3] - cot[2] - cot[1];

int cota[10],add[N];

for(int j = 0;j < N; ++j)

{

add[j] = 0;

}

for(int k = 0;k < 10; ++k)

{

cota[k] = 0;

}

//求该数的每个位上的数字的N次方的和

for(int l = 0;l < 10; ++l)

{

for(int m = 1;m <= cot[l]; ++m)

{

for(int n = 0;n < N; ++n)

{

add[n] += arr[l][n];

while(add[n] > 9)

{

add[n] -= 10;

add[n + 1]++;

}

}

}

}

//判断得到的和是不是一个21位数

if(0 == add[N - 1]) continue;

//计数和中每个数字出现的次数

for(int o = 0;o < N; ++o)

{

cota[add[o]]++;

}

//将和中每个数字出现的次数与该数中每个数字出现的次数进行比较

int flag = 1;

for(int p = 0;p < 10; ++p)

{

if(cot[p] != cota[p])

{

flag = 0;

break;

}

}

//当该数不符合要求时执行下一次循环,不输出该数

if(0 == flag) continue;

for(int q = N - 1;q >= 0; --q)

cout<

cout<

}

}

}

}

}

}

}

}

}

return 0;

}

//该函数用来求x的21次方,并将所求结果存储在数组arr[x]中

void fang(int x)

{

long int a = 0,b = 0,c = 1;

for(int i = N;i > 0; --i)

{

c = c * x;

a = a * x;

b = b * x;

while(b > 9999999)

{

b -= 10000000;

a += 1;

}

while(c > 9999999)

{

c -= 10000000;

b += 1;

while(b > 9999999)

{

b -= 10000000;

a += 1;

}

}

}

int d;

int e = N - 14;

while(a)

{

d = a % 10;

arr[x][N - (e--)] = d;

a = a / 10;

}

e = N - 7;

while(b)

{

d = b % 10;

arr[x][N - (e--)] = d;

b = b / 10;

}

e = N;

while(c)

{

d = c % 10;

arr[x][N - (e--)] = d;

c = c / 10;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值