【C++】 功能算法实现

C++ 功能算法实现



前言


一、基本功能

C++ 真随机数生成方法

//上面链接中网络上的代码解出时间来有些问题,并且起始月份日期只能是1月1日,以下是我修改后的代码

int IfLeapYear(int year)
{
    return (((year%100!=0)&&(year%4==0)) || ((year%100==0)&&(year%400==0)));
}
string Second2Date_2(long long inputSecond)
{
    //秒数转换
    int year___d[2] = {365, 366};
    int year___s[2]     = {365*24*60*60,
                           366*24*60*60};
    int month__d[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                           {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
    int day____s = 24*60*60;
    int hour___s = 60*60;
    int minute_s = 60;
    //起始时间
    int start_year__ = 1996;
    int start_month_ = 9;
    int start_day___ = 29;
    int start_hour__ = 0;
    int start_minute = 0;
    int start_second = 0;

    int out_year__ = start_year__;
    int out_month_ = 1;
    int out_day___ = 1;
    int out_hour__ = 0;
    int out_minute = 0;
    long long out_second ;


    //获取初始秒
    long long tempSecond = inputSecond;
    //将 时:分:秒 转化为 00:00:00
    out_second = tempSecond + start_second+start_minute*minute_s+start_hour__*hour___s;
    //将月份转化为当年1月
    for(int i_mon=1;i_mon<start_month_;i_mon++)
    {
        out_second += month__d[IfLeapYear(start_year__)][i_mon-1]*day____s;
    }
    //将日转化为当年1日
    out_second += (start_day___-1)*day____s;
    ///以下时间基于 xxxx-01-01T00:00:00

    out_day___ = out_second / (long long)day____s;
    out_second = out_second % day____s;

    out_hour__ = out_second / hour___s;
    out_second = out_second % hour___s;

    out_minute = out_second / minute_s;
    out_second = out_second % minute_s;

    while(out_day___ >= year___d[IfLeapYear(out_year__)]) ///$$$$$$$$$$$$$$$$
    {
        out_day___ -= year___d[IfLeapYear(out_year__)];
        out_year__++;
    }

    while(out_day___ >= month__d[IfLeapYear(out_year__)][out_month_-1])
    {
        out_day___ -= month__d[IfLeapYear(out_year__)][out_month_-1];
        out_month_++;
    }

    //cout<<out_year__<<"-"<<out_month_<<"-"<<out_day___<<"T"<<out_hour__<<":"<<out_minute<<":"<<out_second<<endl;

    char* out_C = (char*)malloc(sizeof(char)*1000);
    sprintf(out_C, "%04d-%02d-%02d %02d:%02d:%02d", out_year__, out_month_, out_day___, out_hour__, out_minute, out_second);
    //cout<<"****************"<<out_C<<endl;
    return out_C;
}
tempStr = input_group_name.substr(iInLen+1,input_group_name.length()-iInLen-1);
ceil();//向上舍入为最接近的整数
floor();//向下舍入为最接近的整数
round();//对浮点数进行四舍五入

总结

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值