avatar
fireworks99
keep hungry keep foolish

HDU 2212 打表

Description

int范围内找出:各位数字的阶乘和等于原数字的数

暴力打表

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#define eps 1e-8
#define PI acos(-1.0)
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
#define Close ios::sync_with_stdio(false);

void Debug(char * s)
{
    cout << "-------------  " << s << "  -------------" << '\n';
}

ll fac[20];

void get_fac()
{
    fac[0] = 1;
    for(int i = 1; i <= 12; ++i)
        fac[i] = fac[i - 1] * i;
}

bool check(ll n)
{
    int tem = n;
    ll res = 0;
    while(tem)
    {
        res += fac[tem % 10];
        tem /= 10;
    }
    if(res == n)
        return 1;
    return 0;
}

int main()
{
    freopen("00out.txt", "w", stdout);
    get_fac();
    for(ll i = 1; i <= 2147483647; ++i)
        if(check(i))
            cout << i << ',';
    return 0;
}

定向输出到文件中

time

output

当输出数据量较大时这种方法更为合适

将数据复制下来粘贴到新程序的数组里

复制时去掉最后的那个逗号

new code

#include <iostream>
using namespace std;

int a[] = {1,2,145,40585};///去掉最后一个逗号

int main()
{
    int sz = sizeof(a) / sizeof(int);
    for(int i = 0; i < sz; ++i)
        cout << a[i] << '\n';
    return 0;
}
Site by Baole Zhao | Powered by Hexo | theme PreciousJoy