test

//
//  main.c
//  Test
//
//  Created by 吕颖 on 2019/1/16.
//  Copyright © 2019年 carmen. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int getAction(int num);

int main(int argc, const char * argv[]) {
    int number = 0;
    int actionNum = 0;
    int acount[20] = {0};
    srand((unsigned)time(NULL));
    
    for (int i=0; i<10000; i++){
        number = rand()%10000;
        actionNum = getAction(number);
        acount[actionNum]++;
        
    }
    for(int i=0; i<20; i++){
        printf("%d出现%d次\n", i+1, acount[i]);
    }
    
    
    return 0;
}

int getAction(int num){
    int ret = 0;
    int account[20] = {1433,2399,2533,3211,3333,
        3644,3934,4444,4812,5555,
        5733,6233,6666,6912,7342,
        7777,8201,8888,9219,9999};
    for(int i = 0; i < 20; i++){
        if(num < account[i]){
            ret = i+1;
            break;
        }
    }
    return ret;
//    int ret = 0;
//    if(num < 1423){
//        ret = 1;
//    } else if(num < 2399){
//        ret = 2;
//    } else if(num < 2512){
//        ret = 3;
//    } else if(num < 2784){
//        ret = 4;
//    } else if(num < 3212){
//        ret = 5;
//    } else if(num < 3721){
//        ret = 6;
//    } else if(num < 4012){
//        ret = 7;
//    } else if(num < 4609){
//        ret = 8;
//    } else if(num < 5022){
//        ret = 9;
//    } else if(num < 5412){
//        ret = 10;
//    } else if(num < 5876){
//        ret = 11;
//    } else if(num < 6322){
//        ret = 12;
//    } else if(num < 6541){
//        ret = 13;
//    } else if(num < 6987){
//        ret = 14;
//    } else if(num < 7433){
//        ret = 15;
//    } else if(num < 7845){
//        ret = 16;
//    } else if(num < 8325){
//        ret = 17;
//    } else if(num < 8743){
//        ret = 18;
//    } else if(num < 9509){
//        ret = 19;
//    } else {
//        ret = 0;
//    }
//    return ret;
}

 

转载于:https://my.oschina.net/carmen001/blog/3002041

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值