1~3000所有包含5,6的数(如56,526,1635)的和

#include<iostream>
using namespace std;

const int contain_num[] = {5,6};
const int num_len = sizeof(contain_num)/sizeof(contain_num[0]);
const int MAX = 3000;
bool b_has[10] = {false};

bool if_contain(int n);
int contain_sum();

int  main() 
{
    int sum = contain_sum();
    cout<<sum<<endl;
	return 0;
}

bool if_contain(int n)
{
    int i;
    bool b_rst = true;
    for(i=0; i<num_len; i++)
        b_has[contain_num[i]] = true;
    int temp = n;
    while(temp)
    {
        b_has[temp%10] = false;
        temp /= 10;
    }
    for(i=0; i<num_len; i++)
    {
        if(b_has[contain_num[i]])
        {
            b_rst = false;
            break;
        }
    }

    return b_rst;
}

int contain_sum()
{
    int i, j;
    int sum=0;
    i = 1;
    j = num_len-1;
    while(j--)
        i*=10;
    
    for(; i<MAX; i++)
    {
        if(if_contain(i))
        {
            sum += i;
        }
    }
    return sum;
}

const u16 SINWAVE[4096]={ 2047,2050,2053,2056,2060,2063,2066,2069,2072,2075,2078,2082,2085,2088,2091,2094, 2097,2100,2104,2107,2110,2113,2116,2119,2122,2126,2129,2132,2135,2138,2141,2144, 2147,2151,2154,2157,2160,2163,2166,2169,2173,2176,2179,2182,2185,2188,2191,2195, 2198,2201,2204,2207,2210,2213,2216,2220,2223,2226,2229,2232,2235,2238,2241,2245, 2248,2251,2254,2257,2260,2263,2266,2270,2273,2276,2279,2282,2285,2288,2291,2295, 2298,2301,2304,2307,2310,2313,2316,2320,2323,2326,2329,2332,2335,2338,2341,2344, 2348,2351,2354,2357,2360,2363,2366,2369,2372,2375,2379,2382,2385,2388,2391,2394, 2397,2400,2403,2406,2410,2413,2416,2419,2422,2425,2428,2431,2434,2437,2440,2443, 2447,2450,2453,2456,2459,2462,2465,2468,2471,2474,2477,2480,2483,2487,2490,2493, 2496,2499,2502,2505,2508,2511,2514,2517,2520,2523,2526,2529,2532,2535,2539,2542, 2545,2548,2551,2554,2557,2560,2563,2566,2569,2572,2575,2578,2581,2584,2587,2590, 2593,2596,2599,2602,2605,2608,2611,2614,2617,2620,2623,2626,2629,2632,2635,2638, 2641,2645,2648,2651,2654,2657,2660,2663,2666,2668,2671,2674,2677,2680,2683,2686, 2689,2692,2695,2698,2701,2704,2707,2710,2713,2716,2719,2722,2725,2728,2731,2734, 2737,2740,2743,2746,2749,2752,2755,2758,2761,2763,2766,2769,2772,2775,2778,2781, 2784,2787,2790,2793,2796,2799,2802,2805,2807,2810,2813,2816,2819,2822,2825,2828, 2831,2834,2837,2839,2842,2845,2848,2851,2854,2857,2860,2863,2865,2868,2871,2874, 2877,2880,2883,2886,2888,2891,2894,2897,2900,2903,2906,2908,2911,2914,2917,2920, 2923,2925,2928,2931,2934,2937,2940,2942,2945,2948,2951,2954,2957,2959,2962,2965, 2968,2971,2973,2976,2979,2982,2985,2987,2990,2993,2996,2999,3001,3004,3007,3010, 3012,3015,3018,3021,3023,3026,3029,3032,3034,3037,3040,3043,3045,3048,3051,3054, 3056,3059,3062,3065,3067,3070,3073,3076,3078,3081,3084,3086,3089,3092,3094,3097, 3100,3103,3105,3108,3111,3113,3116,3119,3121,3124,3127,3129,3132,3135,3137,3140, 3143,3145,3148,3151,3153,3156,3159,3161,3164,3166,3169,3172,3174,3177,3180,3182, 3185,3187,3190,3193,3195,3198,3200,3203,3206,3208,3211,3213,3216,3219,3221,3224, 3226,3229,3231,3234,3236,3239,3242,3244,3247,3249,3252,3254,3257,3259,3262,3264, 3267,3269,3272,3275,3277,3280,3282,3285,3287,3290,3292,3295,3297,3300,3302,3304, 3307,3309,3312,3314,3317,3319,3322,3324,3327,3329,3332,3334,3336,3339,3341,3344, 3346,3349,3351,3353,3356,3358,3361,3363,3366,3368,3370,3373,3375,3377,3380,3382, 3385,3387,3389,3392,3394,3396,3399,3401,3404,3406,3408,3411,3413,3415,3418,3420, 3422,3425,3427,3429,3432,3434,3436,3439,3441,3443,3445,3448,3450,3452,3455,3457, 3459,3461,3464,3466,3468,3470,3473,3475,3477,3479,3482,3484,3486,3488,3491,3493, 3495,3497,3500,3502,3504,3506,3508,3511,3513,3515,3517,3519,3521,3524,3526,3528, 3530,3532,3534,3537,3539,3541,3543,3545,3547,3550,3552,3554,3556,3558,3560,3562, 3564,3566,3569,3571,3573,3575,3577,3579,3581,3583,3585,3587,3589,3591,3594,3596, 3598,3600,3602,3604,3606,3608,3610,3612,3614,3616,3618,3620,3622,3624,3626,3628, 3630,3632,3634,3636,3638,3640,3642,3644,3646,3648,3650,3652,3654,3656,3658,3659, 3661,3663,3665,3667,3669,3671,3673,3675,3677,3679,3681,3682,3684,3686,3688,3690, 3692,3694,3696,3697,3699,3701,3703,3705,3707,3709,3710,3712,3714,3716,3718,3719, 3721,3723,3725,3727,3728,3730,3732,3734,3736,3737,3739,3741,3743,3744,3746,3748, 3750,3751,3753,3755,3757,3758,3760,3762,3764,3765,3767,3769,3770,3772,3774,3775, 3777,3779,3780,3782,3784,3785,3787,3789,3790,3792,3794,3795,3797,3799,3800,3802, 3803,3805,3807,3808,3810,3811,3813,3815,3816,3818,3819,3821,3823,3824,3826,3827, 3829,3830,3832,3833,3835,3836,3838,3839,3841,3843,3844,3846,3847,3849,3850,3852, 3853,3854,3856,3857,3859,3860,3862,3863,3865,3866,3868,3869,3870,3872,3873,3875, 3876,3878,3879,3880,3882,3883,3885,3886,3887,3889,3890,3891,3893,3894,3895,3897, 3898,3899,3901,3902,3903,3905,3906,3907,3909,3910,3911,3913,3914,3915,3917,3918, 3919,3920,3922,3923,3924,3925,3927,3928,3929,3930,3932,3933,3934,3935,3936,3938, 3939,3940,3941,3942,3944,3945,3946,3947,3948,3950,3951,3952,3953,3954,3955,3956, 3958,3959,3960,3961,3962,3963,3964,3965,3966,3968,3969,3970,3971,3972,3973,3974, 3975,3976,3977,3978,3979,3980,3981,3982,3983,3984,3985,3986,3987,3988,3989,3990, 3991,3992,3993,3994,3995,3996,3997,3998,3999,4000,4001,4002,4003,4004,4005,4006, 4007,4007,4008,4009,4010,4011,4012,4013,4014,4015,4015,4016,4017,4018,4019,4020, 4021,4021,4022,4023,4024,4025,4025,4026,4027,4028,4029,4029,4030,4031,4032,4033, 4033,4034,4035,4036,4036,4037,4038,4039,4039,4040,4041,4041,4042,4043,4044,4044, 4045,4046,4046,4047,4048,4048,4049,4050,4050,4051,4052,4052,4053,4053,4054,4055, 4055,4056,4057,4057,4058,4058,4059,4059,4060,4061,4061,4062,4062,4063,4063,4064, 4064,4065,4066,4066,4067,4067,4068,4068,4069,4069,4070,4070,4071,4071,4072,4072, 4072,4073,4073,4074,4074,4075,4075,4076,4076,4076,4077,4077,4078,4078,4078,4079, 4079,4080,4080,4080,4081,4081,4081,4082,4082,4082,4083,4083,4083,4084,4084,4084, 4085,4085,4085,4086,4086,4086,4086,4087,4087,4087,4088,4088,4088,4088,4089,4089, 4089,4089,4089,4090,4090,4090,4090,4090,4091,4091,4091,4091,4091,4092,4092,4092, 4092,4092,4092,4093,4093,4093,4093,4093,4093,4093,4093,4093,4094,4094,4094,4094, 4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094, 4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094,4094, 4094,4094,4094,4094,4094,4093,4093,4093,4093,4093,4093,4093,4093,4092,4092,4092, 4092,4092,4092,4092,4091,4091,4091,4091,4091,4090,4090,4090,4090,4090,4089,4089, 4089,4089,4088,4088,4088,4088,4087,4087,4087,4087,4086,4086,4086,4085,4085,4085, 4085,4084,4084,4084,4083,4083,4083,4082,4082,4082,4081,4081,4081,4080,4080,4079, 4079,4079,4078,4078,4077,4077,4077,4076,4076,4075,4075,4074,4074,4074,4073,4073, 4072,4072,4071,4071,4070,4070,4069,4069,4068,4068,4067,4067,4066,4066,4065,4065, 4064,4064,4063,4063,4062,4061,4061,4060,4060,4059,4059,4058,4057,4057,4056,4056, 4055,4054,4054,4053,4052,4052,4051,4051,4050,4049,4049,4048,4047,4047,4046,4045, 4045,4044,4043,4042,4042,4041,4040,4040,4039,4038,4037,4037,4036,4035,4034,4034, 4033,4032,4031,4031,4030,4029,4028,4027,4027,4026,4025,4024,4023,4023,4022,4021, 4020,4019,4018,4018,4017,4016,4015,4014,4013,4012,4011,4011,4010,4009,4008,4007, 4006,4005,4004,4003,4002,4001,4001,4000,3999,3998,3997,3996,3995,3994,3993,3992, 3991,3990,3989,3988,3987,3986,3985,3984,3983,3982,3981,3980,3979,3978,3977,3976, 3974,3973,3972,3971,3970,3969,3968,3967,3966,3965,3964,3963,3961,3960,3959,3958, 3957,3956,3955,3954,3952,3951,3950,3949,3948,3947,3945,3944,3943,3942,3941,3939, 3938,3937,3936,3935,3933,3932,3931,3930,3928,3927,3926,3925,3924,3922,3921,3920, 3918,3917,3916,3915,3913,3912,3911,3909,3908,3907,3905,3904,3903,3902,3900,3899, 3897,3896,3895,3893,3892,3891,3889,3888,3887,3885,3884,3882,3881,3880,3878,3877, 3875,3874,3873,3871,3870,3868,3867,3865,3864,3863,3861,3860,3858,3857,3855,3854, 3852,3851,3849,3848,3846,3845,3843,3842,3840,3839,3837,3836,3834,3833,3831,3830, 3828,3826,3825,3823,3822,3820,3819,3817,3815,3814,3812,3811,3809,3807,3806,3804, 3803,3801,3799,3798,3796,3795,3793,3791,3790,3788,3786,3785,3783,3781,3780,3778, 3776,3775,3773,3771,3770,3768,3766,3764,3763,3761,3759,3758,3756,3754,3752,3751, 3749,3747,3745,3744,3742,3740,3738,3737,3735,3733,3731,3729,3728,3726,3724,3722, 3720,3719,3717,3715,3713,3711,3709,3708,3706,3704,3702,3700,3698,3697,3695,3693, 3691,3689,3687,3685,3683,3681,3680,3678,3676,3674,3672,3670,3668,3666,3664,3662, 3660,3659,3657,3655,3653,3651,3649,3647,3645,3643,3641,3639,3637,3635,3633,3631, 3629,3627,3625,3623,3621,3619,3617,3615,3613,3611,3609,3607,3605,3603,3601,3599, 3597,3595,3593,3590,3588,3586,3584,3582,3580,3578,3576,3574,3572,3570,3568,3565, 3563,3561,3559,3557,3555,3553,3551,3548,3546,3544,3542,3540,3538,3536,3533,3531, 3529,3527,3525,3523,3520,3518,3516,3514,3512,3509,3507,3505,3503,3501,3498,3496, 3494,3492,3490,3487,3485,3483,3481,3478,3476,3474,3472,3469,3467,3465,3463,3460, 3458,3456,3453,3451,3449,3447,3444,3442,3440,3437,3435,3433,3430,3428,3426,3423, 3421,3419,3416,3414,3412,3409,3407,3405,3402,3400,3398,3395,3393,3391,3388,3386, 3383,3381,3379,3376,3374,3372,3369,3367,3364,3362,3359,3357,3355,3352,3350,3347, 3345,3343,3340,3338,3335,3333,3330,3328,3325,3323,3321,3318,3316,3313,3311,3308, 3306,3303,3301,3298,3296,3293,3291,3288,3286,3283,3281,3278,3276,3273,3271,3268, 3266,3263,3261,3258,3256,3253,3250,3248,3245,3243,3240,3238,3235,3233,3230,3228, 3225,3222,3220,3217,3215,3212,3209,3207,3204,3202,3199,3197,3194,3191,3189,3186, 3183,3181,3178,3176,3173,3170,3168,3165,3162,3160,3157,3155,3152,3149,3147,3144, 3141,3139,3136,3133,3131,3128,3125,3123,3120,3117,3115,3112,3109,3107,3104,3101, 3099,3096,3093,3090,3088,3085,3082,3080,3077,3074,3071,3069,3066,3063,3061,3058, 3055,3052,3050,3047,3044,3041,3039,3036,3033,3030,3028,3025,3022,3019,3017,3014, 3011,3008,3005,3003,3000,2997,2994,2992,2989,2986,2983,2980,2978,2975,2972,2969, 2966,2964,2961,2958,2955,2952,2950,2947,2944,2941,2938,2935,2933,2930,2927,2924, 2921,2918,2916,2913,2910,2907,2904,2901,2898,2896,2893,2890,2887,2884,2881,2878, 2875,2873,2870,2867,2864,2861,2858,2855,2852,2850,2847,2844,2841,2838,2835,2832, 2829,2826,2823,2821,2818,2815,2812,2809,2806,2803,2800,2797,2794,2791,2788,2786, 2783,2780,2777,2774,2771,2768,2765,2762,2759,2756,2753,2750,2747,2744,2741,2738, 2735,2733,2730,2727,2724,2721,2718,2715,2712,2709,2706,2703,2700,2697,2694,2691, 2688,2685,2682,2679,2676,2673,2670,2667,2664,2661,2658,2655,2652,2649,2646,2643, 2640,2637,2634,2631,2628,2625,2622,2619,2616,2613,2610,2607,2604,2601,2598,2595, 2592,2589,2586,2583,2580,2577,2574,2570,2567,2564,2561,2558,2555,2552,2549,2546, 2543,2540,2537,2534,2531,2528,2525,2522,2519,2516,2513,2510,2506,2503,2500,2497, 2494,2491,2488,2485,2482,2479,2476,2473,2470,2467,2463,2460,2457,2454,2451,2448, 2445,2442,2439,2436,2433,2430,2426,2423,2420,2417,2414,2411,2408,2405,2402,2399, 2396,2392,2389,2386,2383,2380,2377,2374,2371,2368,2365,2361,2358,2355,2352,2349, 2346,2343,2340,2337,2334,2330,2327,2324,2321,2318,2315,2312,2309,2305,2302,2299, 2296,2293,2290,2287,2284,2281,2277,2274,2271,2268,2265,2262,2259,2256,2252,2249, 2246,2243,2240,2237,2234,2231,2227,2224,2221,2218,2215,2212,2209,2205,2202,2199, 2196,2193,2190,2187,2184,2180,2177,2174,2171,2168,2165,2162,2158,2155,2152,2149, 2146,2143,2140,2137,2133,2130,2127,2124,2121,2118,2115,2111,2108,2105,2102,2099, 2096,2093,2089,2086,2083,2080,2077,2074,2071,2067,2064,2061,2058,2055,2052,2049, 2045,2042,2039,2036,2033,2030,2027,2023,2020,2017,2014,2011,2008,2005,2001,1998, 1995,1992,1989,1986,1983,1979,1976,1973,1970,1967,1964,1961,1957,1954,1951,1948, 1945,1942,1939,1936,1932,1929,1926,1923,1920,1917,1914,1910,1907,1904,1901,1898, 1895,1892,1889,1885,1882,1879,1876,1873,1870,1867,1863,1860,1857,1854,1851,1848, 1845,1842,1838,1835,1832,1829,1826,1823,1820,1817,1813,1810,1807,1804,1801,1798, 1795,1792,1789,1785,1782,1779,1776,1773,1770,1767,1764,1760,1757,1754,1751,1748, 1745,1742,1739,1736,1733,1729,1726,1723,1720,1717,1714,1711,1708,1705,1702,1698, 1695,1692,1689,1686,1683,1680,1677,1674,1671,1668,1664,1661,1658,1655,1652,1649, 1646,1643,1640,1637,1634,1631,1627,1624,1621,1618,1615,1612,1609,1606,1603,1600, 1597,1594,1591,1588,1584,1581,1578,1575,1572,1569,1566,1563,1560,1557,1554,1551, 1548,1545,1542,1539,1536,1533,1530,1527,1524,1520,1517,1514,1511,1508,1505,1502, 1499,1496,1493,1490,1487,1484,1481,1478,1475,1472,1469,1466,1463,1460,1457,1454, 1451,1448,1445,1442,1439,1436,1433,1430,1427,1424,1421,1418,1415,1412,1409,1406, 1403,1400,1397,1394,1391,1388,1385,1382,1379,1376,1373,1370,1367,1364,1361,1359, 1356,1353,1350,1347,1344,1341,1338,1335,1332,1329,1326,1323,1320,1317,1314,1311, 1308,1306,1303,1300,1297,1294,1291,1288,1285,1282,1279,1276,1273,1271,1268,1265, 1262,1259,1256,1253,1250,1247,1244,1242,1239,1236,1233,1230,1227,1224,1221,1219, 1216,1213,1210,1207,1204,1201,1198,1196,1193,1190,1187,1184,1181,1178,1176,1173, 1170,1167,1164,1161,1159,1156,1153,1150,1147,1144,1142,1139,1136,1133,1130,1128, 1125,1122,1119,1116,1114,1111,1108,1105,1102,1100,1097,1094,1091,1089,1086,1083, 1080,1077,1075,1072,1069,1066,1064,1061,1058,1055,1053,1050,1047,1044,1042,1039, 1036,1033,1031,1028,1025,1023,1020,1017,1014,1012,1009,1006,1004,1001,998,995, 993,990,987,985,982,979,977,974,971,969,966,963,961,958,955,953,950,947,945,942, 939,937,934,932,929,926,924,921,918,916,913,911,908,905,903,900,897,895,892,890, 887,885,882,879,877,874,872,869,866,864,861,859,856,854,851,849,846,844,841,838, 836,833,831,828,826,823,821,818,816,813,811,808,806,803,801,798,796,793,791,788, 786,783,781,778,776,773,771,769,766,764,761,759,756,754,751,749,747,744,742,739, 737,735,732,730,727,725,722,720,718,715,713,711,708,706,703,701,699,696,694,692, 689,687,685,682,680,678,675,673,671,668,666,664,661,659,657,654,652,650,647,645, 643,641,638,636,634,631,629,627,625,622,620,618,616,613,611,609,607,604,602,600, 598,596,593,591,589,587,585,582,580,578,576,574,571,569,567,565,563,561,558,556, 554,552,550,548,546,543,541,539,537,535,533,531,529,526,524,522,520,518,516,514, 512,510,508,506,504,501,499,497,495,493,491,489,487,485,483,481,479,477,475,473, 471,469,467,465,463,461,459,457,455,453,451,449,447,445,443,441,439,437,435,434, 432,430,428,426,424,422,420,418,416,414,413,411,409,407,405,403,401,399,397,396, 394,392,390,388,386,385,383,381,379,377,375,374,372,370,368,366,365,363,361,359, 357,356,354,352,350,349,347,345,343,342,340,338,336,335,333,331,330,328,326,324, 323,321,319,318,316,314,313,311,309,308,306,304,303,301,299,298,296,295,293,291, 290,288,287,285,283,282,280,279,277,275,274,272,271,269,268,266,264,263,261,260, 258,257,255,254,252,251,249,248,246,245,243,242,240,239,237,236,234,233,231,230, 229,227,226,224,223,221,220,219,217,216,214,213,212,210,209,207,206,205,203,202, 201,199,198,197,195,194,192,191,190,189,187,186,185,183,182,181,179,178,177,176, 174,173,172,170,169,168,167,166,164,163,162,161,159,158,157,156,155,153,152,151, 150,149,147,146,145,144,143,142,140,139,138,137,136,135,134,133,131,130,129,128, 127,126,125,124,123,122,121,120,118,117,116,115,114,113,112,111,110,109,108,107, 106,105,104,103,102,101,100,99,98,97,96,95,94,93,93,92,91,90,89,88,87,86,85,84,83, 83,82,81,80,79,78,77,76,76,75,74,73,72,71,71,70,69,68,67,67,66,65,64,63,63,62,61, 60,60,59,58,57,57,56,55,54,54,53,52,52,51,50,49,49,48,47,47,46,45,45,44,43,43,42, 42,41,40,40,39,38,38,37,37,36,35,35,34,34,33,33,32,31,31,30,30,29,29,28,28,27, 27,26,26,25,25,24,24,23,23,22,22,21,21,20,20,20,19,19,18,18,17,17,17,16,16,15,15, 15,14,14,13,13,13,12,12,12,11,11,11,10,10,10,9,9,9,9,8,8,8,7,7,7,7,6,6,6,6,5,5, 5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2, 2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,7,7,7,8,8,8,8,9,9,9,10,10,10,11,11, 11,12,12,12,13,13,13,14,14,14,15,15,16,16,16,17,17,18,18,18,19,19,20,20,21,21,22, 22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,30,30,31,31,32,32,33,33,34,35,35,36, 36,37,37,38,39,39,40,41,41,42,42,43,44,44,45,46,46,47,48,48,49,50,50,51,52,53, 53,54,55,55,56,57,58,58,59,60,61,61,62,63,64,65,65,66,67,68,69,69,70,71,72,73,73, 74,75,76,77,78,79,79,80,81,82,83,84,85,86,87,87,88,89,90,91,92,93,94,95,96,97,98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118, 119,120,121,122,123,124,125,126,128,129,130,131,132,133,134,135,136,138,139,140, 141,142,143,144,146,147,148,149,150,152,153,154,155,156,158,159,160,161,162,164, 165,166,167,169,170,171,172,174,175,176,177,179,180,181,183,184,185,187,188,189, 191,192,193,195,196,197,199,200,201,203,204,205,207,208,209,211,212,214,215,216, 218,219,221,222,224,225,226,228,229,231,232,234,235,237,238,240,241,242,244,245, 247,248,250,251,253,255,256,258,259,261,262,264,265,267,268,270,271,273,275,276, 278,279,281,283,284,286,287,289,291,292,294,295,297,299,300,302,304,305,307,309, 310,312,314,315,317,319,320,322,324,325,327,329,330,332,334,336,337,339,341,343, 344,346,348,350,351,353,355,357,358,360,362,364,366,367,369,371,373,375,376,378, 380,382,384,385,387,389,391,393,395,397,398,400,402,404,406,408,410,412,413,415, 417,419,421,423,425,427,429,431,433,435,436,438,440,442,444,446,448,450,452,454, 456,458,460,462,464,466,468,470,472,474,476,478,480,482,484,486,488,490,492,494, 496,498,500,503,505,507,509,511,513,515,517,519,521,523,525,528,530,532,534,536, 538,540,542,544,547,549,551,553,555,557,560,562,564,566,568,570,573,575,577,579, 581,583,586,588,590,592,594,597,599,601,603,606,608,610,612,615,617,619,621,624, 626,628,630,633,635,637,639,642,644,646,649,651,653,655,658,660,662,665,667,669, 672,674,676,679,681,683,686,688,690,693,695,698,700,702,705,707,709,712,714,717, 719,721,724,726,728,731,733,736,738,741,743,745,748,750,753,755,758,760,762,765, 767,770,772,775,777,780,782,785,787,790,792,794,797,799,802,804,807,809,812,814, 817,819,822,825,827,830,832,835,837,840,842,845,847,850,852,855,858,860,863,865, 868,870,873,875,878,881,883,886,888,891,894,896,899,901,904,907,909,912,914,917, 920,922,925,928,930,933,935,938,941,943,946,949,951,954,957,959,962,965,967,970, 973,975,978,981,983,986,989,991,994,997,1000,1002,1005,1008,1010,1013,1016,1018, 1021,1024,1027,1029,1032,1035,1038,1040,1043,1046,1049,1051,1054,1057,1060,1062, 1065,1068,1071,1073,1076,1079,1082,1084,1087,1090,1093,1095,1098,1101,1104,1107, 1109,1112,1115,1118,1121,1123,1126,1129,1132,1135,1137,1140,1143,1146,1149,1152, 1154,1157,1160,1163,1166,1169,1171,1174,1177,1180,1183,1186,1188,1191,1194,1197, 1200,1203,1206,1208,1211,1214,1217,1220,1223,1226,1229,1231,1234,1237,1240,1243, 1246,1249,1252,1255,1257,1260,1263,1266,1269,1272,1275,1278,1281,1284,1287,1289, 1292,1295,1298,1301,1304,1307,1310,1313,1316,1319,1322,1325,1328,1331,1333,1336, 1339,1342,1345,1348,1351,1354,1357,1360,1363,1366,1369,1372,1375,1378,1381,1384, 1387,1390,1393,1396,1399,1402,1405,1408,1411,1414,1417,1420,1423,1426,1428,1431, 1434,1437,1440,1443,1446,1449,1453,1456,1459,1462,1465,1468,1471,1474,1477,1480, 1483,1486,1489,1492,1495,1498,1501,1504,1507,1510,1513,1516,1519,1522,1525,1528, 1531,1534,1537,1540,1543,1546,1549,1552,1555,1559,1562,1565,1568,1571,1574,1577, 1580,1583,1586,1589,1592,1595,1598,1601,1604,1607,1611,1614,1617,1620,1623,1626, 1629,1632,1635,1638,1641,1644,1647,1651,1654,1657,1660,1663,1666,1669,1672,1675, 1678,1681,1684,1688,1691,1694,1697,1700,1703,1706,1709,1712,1715,1719,1722,1725, 1728,1731,1734,1737,1740,1743,1746,1750,1753,1756,1759,1762,1765,1768,1771,1774, 1778,1781,1784,1787,1790,1793,1796,1799,1803,1806,1809,1812,1815,1818,1821,1824, 1828,1831,1834,1837,1840,1843,1846,1849,1853,1856,1859,1862,1865,1868,1871,1874, 1878,1881,1884,1887,1890,1893,1896,1899,1903,1906,1909,1912,1915,1918,1921,1925, 1928,1931,1934,1937,1940,1943,1947,1950,1953,1956,1959,1962,1965,1968,1972,1975, 1978,1981,1984,1987,1990,1994,1997,2000,2003,2006,2009,2012,2016,2019,2022,2025, 2028,2031,2034,2038,2041,2044,2047 }; #define NPT 1024 // FFT?? #define PI 3.1415926 // p? #define PI2 2*PI // 2p? #define SAMPLING_FREQ 10240 // ????(Hz) #define FFT_SIZE 1024 // FFT?? #define FMIN 42950 // DDS?????? #define DDS_CLOCK 1000000 // DDS????(Hz) = 1MHz #define FREQ_SCALE (4294967296.0f / DDS_CLOCK) // ???????? (2^32 / DDS??) // ????????????? // ???????? volatile float target_freq1 = 100.0f; // ????1(Hz) volatile float target_freq2 = 200.00f/0.34; // ????2(Hz) volatile uint32_t freq1_step = 0; // ????1 volatile uint32_t freq2_step = 0; // ????2 u16 real[1024]; // ???? u8 sampling = 0; // ??????? u16 freq_indices[2]; // ?????? float freq_values[2]; // ??????? u8 lcd_show_buf[128]; // ???? void DDS_Value_Init(void); void DAC_Config(void); void ADC_Config(void); void NVIC2_Config(void); void NVIC3_Config(void); void TIM2_Config(void); void TIM3_Config(void); void PowerMag(u16 nfill); void PowerPhase(u16 nfill); void Find_Freq(u16 *freq_indices, float *freq_values); void update_freq_steps(void); s32 lBUFIN[NPT]; /* Complex input vector */ s32 lBUFOUT[NPT]; /* Complex output vector */ s32 lBUFMAG[NPT]; /* Magnitude vector */ s32 lBUFPHASE[NPT]; /* Phase vector */ // ?????? void update_freq_steps(void) { freq1_step = (uint32_t)(target_freq1 * FREQ_SCALE); freq2_step = (uint32_t)(target_freq2 * FREQ_SCALE); } int main (void) { u16 i = 0; uint8_t key_value = 0; /*??????,??????????????*/ SystemInit(); TIM2_Config(); DDS_Value_Init(); DAC_Config(); // ???????? update_freq_steps(); TIM_Cmd(TIM2, ENABLE); ADC_Config(); TIM3_Config(); TIM_Cmd(TIM3, ENABLE); while (1) { // ??????(??:??PA0?PA1?????) // ???????? if (sampling == 1) { TIM_Cmd(TIM3, DISABLE); for (i = 0; i < NPT; i++) lBUFIN[i] = real[i] << 16; cr4_fft_1024_stm32(lBUFOUT, lBUFIN, NPT); PowerMag(NPT); Find_Freq(freq_indices, freq_values); sampling = 0; TIM_Cmd(TIM3, ENABLE); } } } u16 wave1[4096], wave2[4096]; void DDS_Value_Init(void) { u16 i = 0; for (i = 0; i < 4096; i++) { wave1[i] = SINWAVE[i] * 1.5 / 2.5; wave2[i] = SINWAVE[i] * 1.5 / 2.5; } } void DAC_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; DAC_InitTypeDef DAC_InitStructure; /* AFIO and GPIOA Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* Configure DAC channe1 and DAC channel2 outputs pins */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); /* DAC channel2 Configuration */ DAC_Init(DAC_Channel_2, &DAC_InitStructure); /* Enable DAC Channel1 */ DAC_Cmd(DAC_Channel_1, ENABLE); /* Enable DAC Channel2 */ DAC_Cmd(DAC_Channel_2, ENABLE); } void ADC_Config(void) { ADC_InitTypeDef ADC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); RCC_ADCCLKConfig(RCC_PCLK2_Div4); //PCLK2 4??=18MHz /* ADC1 Configuration */ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel10 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_13Cycles5); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); //??ADC??????? /* Check the end of ADC1 reset calibration register */ while (ADC_GetResetCalibrationStatus(ADC1)); //??ADC?????????? /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); //????????? /* Check the end of ADC1 calibration */ while (ADC_GetCalibrationStatus(ADC1)); //??ADC???????? /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); //????????? } void NVIC2_Config(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); /*?????*/ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; /*??IRQ??*/ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; /*?????*/ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; /*????*/ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void NVIC3_Config(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); /*?????*/ NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; /*??IRQ??*/ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; /*?????*/ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; /*????*/ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } // ??TIM2?1MHz void TIM2_Config(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_DeInit(TIM2); TIM_TimeBaseStructure.TIM_Period = 71; // 72MHz / (71+1) = 1MHz TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_ClearFlag(TIM2, TIM_FLAG_Update); TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); NVIC2_Config(); } void TIM3_Config(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); TIM_DeInit(TIM3); TIM_TimeBaseStructure.TIM_Period = 6391; /*??????*/ TIM_TimeBaseStructure.TIM_Prescaler = 10; /*??????*/ //????fc=10.24Khz TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; /*??????*/ TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); TIM_ClearFlag(TIM3, TIM_FLAG_Update); TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); NVIC3_Config(); } void TIM2_IRQHandler(void) { static u32 a1, b1, dac_value1, dac_value2; if (TIM_GetFlagStatus(TIM2, TIM_FLAG_Update) == SET) { TIM_ClearFlag(TIM2, TIM_FLAG_Update); /*???????*/ // ???????????? a1 += freq1_step; b1 += freq2_step; dac_value1 = wave1[(a1 >> 20) % 4096]; dac_value2 = wave2[(b1 >> 20) % 4096]; DAC_SetDualChannelData(DAC_Align_12b_R, dac_value1, dac_value2); } } void TIM3_IRQHandler(void) { static u16 j = 0; if (TIM_GetFlagStatus(TIM3, TIM_FLAG_Update) == SET) { TIM_ClearFlag(TIM3, TIM_FLAG_Update); /*???????*/ if (j < 1024) { real[j] = ADC_GetConversionValue(ADC1); j++; } else { TIM_Cmd(TIM3, DISABLE); sampling = 1; j = 0; } } } void PowerMag(u16 nfill) { s16 lX, lY; u16 i = 0; float X,Y,Mag; for (i = 0; i < nfill; i++) { lX = (lBUFOUT[i] << 16) >> 16; /* sine_cosine --> cos */ lY = (lBUFOUT[i] >> 16); /* sine_cosine --> sin */ X = nfill * ((float)lX) / 32768; Y = nfill * ((float)lY) / 32768; Mag = sqrt(X * X + Y * Y) / nfill; if (i == 0) lBUFMAG[i] = (uint32_t)(Mag * 32768); else lBUFMAG[i] = (uint32_t)(Mag * 65536); } } void PowerPhase(u16 nfill) { int32_t lX, lY; u16 i = 0; float X,Y,phase; for (i = 0; i < nfill / 2; i++) { lX = (lBUFOUT[i] << 16) >> 16; /* ??16bit,sine_cosine --> cos */ lY = (lBUFOUT[i] >> 16); /* ??16bit,sine_cosine --> sin */ X = NPT * ((float)lX) / 32768; Y = NPT * ((float)lY) / 32768; phase = atan(Y / X); if (Y >= 0) { if (X >= 0) ; else phase += PI; } else { if (X >= 0) phase += PI2; else phase += PI; } lBUFPHASE[i] = phase * 180.0 / PI; } } // ?????????(???????????) void Find_Freq(u16 *freq_indices, float *freq_values) { u16 max1 = 0, max2 = 0, i = 0; u16 idx1 = 0, idx2 = 0; // ???????? for (i = 1; i <= FFT_SIZE/2; i++) { if (lBUFMAG[i] > 100) { if (lBUFMAG[i] > max1) { max2 = max1; idx2 = idx1; max1 = lBUFMAG[i]; idx1 = i; } else if (lBUFMAG[i] > max2) { max2 = lBUFMAG[i]; idx2 = i; } } } // ???? freq_indices[0] = idx1; freq_indices[1] = idx2; // ??????????? for (i = 0; i < 2; i++) { u16 idx = freq_indices[i]; if (idx > 0 && idx < FFT_SIZE/2 - 1) { float y0 = (float)lBUFMAG[idx-1]; float y1 = (float)lBUFMAG[idx]; float y2 = (float)lBUFMAG[idx+1]; // ???????:delta = (y2 - y0) / (2 * (2*y1 - y0 - y2)) float delta = 0.5f * (y2 - y0) / (2.0f * y1 - y0 - y2); // ??????? freq_values[i] = (idx + delta) * SAMPLING_FREQ / FFT_SIZE; } else { // ??????????? freq_values[i] = idx * SAMPLING_FREQ / FFT_SIZE; } } }解释一下代码
最新发布
05-16
### 回答1: 我们可以用循环来遍历1~100之间的所有,然后用取余运算判断该是否包含6,如果包含,则累加到一个变量中: ```python sum = 0 for i in range(1, 101): if i % 10 == 6 or i // 10 == 6: sum += i print(sum) ``` 这里用到了取余运算 `%`,它可以得到一个除以另一个的余。例如,`7 % 3` 的结果为1,因为7除以3等于2余1。这里我们使用 `i % 10` 来判断个位是否为6,使用 `i // 10` 来判断十位是否为6,其中 `//` 是整除运算符,可以得到一个除以另一个的整部分。例如,`17 // 10` 的结果为1,因为17除以10的整部分为1。 最终的结果为:816。 ### 回答2: 1100以内所有含有6的分别为6、16、26、36、46、56、60、61、62、63、64、65、66、67、68、69、76、86、96。将这些相加得到的为: 6+16+26+36+46+56+60+61+62+63+64+65+66+67+68+69+76+86+96=1020。 所以,1100以内所有含有6的1020。 ### 回答3: 要计算1~100以内所有含6的,我们可以使用循环来依次判断每个是否含有6,并将满足条件的累加起来。 算法可以按照以下步骤进行: 1. 初始化一个变量sum为0,用于保存满足条件的字的。 2. 使用一个循环,从1遍历到100。 3. 在每次循环中,判断当前的是否含有6。可以将该转换为字符串,然后使用字符串中的查找函(如Python中的str.find())来判断是否包含字符"6"。 4. 如果当前含有6,则将该累加到sum变量中。 5. 循环结束后,sum变量即为所求的含有6的字的。 以下是一个示例的Python代码实现: ```python sum = 0 for i in range(1, 101): if str(i).find('6') != -1: sum += i print("1~100以内所有含6的为:", sum) ``` 最后运行该代码,即可得到1~100以内所有含6的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值