MarkSix calculator

本文介绍了一个基于C++的彩票数据分析程序,该程序从文件中读取彩票数据,并统计了每种尾号出现的次数及最长未出现的周期。通过解析字符串数据并存储到结构体数组中,最终输出统计结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include "iostream"
#include "string.h"
#include "iostream"
#include "fstream"
#include <vector>
#include <algorithm>

using namespace std;

char ch[100];
struct msd //marksixdata
{
int year;
int term;
int n_norm[6];
int n_special;
};
vector<msd> vec_msd;
msd msd_temp;


//void seperate(char* pch_data)
void GetData(string str_data)
{
//cout<<str_data.c_str()<<endl;

string str_data_temp;
int n_EndPos = 0;
int n_BeginPos = 0;

/*----------------------------------------------------------------------------------------------*/
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
// cout << n_EndPos <<endl;
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.year = atoi(str_data_temp.c_str());
//Extract year
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/*----------------------------------------------------------------------------------------------*/
n_BeginPos = str_data.find_first_not_of(' ', n_EndPos);
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.term = atoi(str_data_temp.c_str());
//
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

/*----------------------------------------------------------------------------------------------*/
n_BeginPos = str_data.find_first_not_of(' ', n_EndPos);
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.n_norm[0] = atoi(str_data_temp.c_str());
//
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

/*----------------------------------------------------------------------------------------------*/
n_BeginPos = str_data.find_first_not_of(' ', n_EndPos);
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.n_norm[1] = atoi(str_data_temp.c_str());
//
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/*----------------------------------------------------------------------------------------------*/
n_BeginPos = str_data.find_first_not_of(' ', n_EndPos);
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.n_norm[2] = atoi(str_data_temp.c_str());
//
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/*----------------------------------------------------------------------------------------------*/
n_BeginPos = str_data.find_first_not_of(' ', n_EndPos);
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.n_norm[3] = atoi(str_data_temp.c_str());
//
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/*----------------------------------------------------------------------------------------------*/
n_BeginPos = str_data.find_first_not_of(' ', n_EndPos);
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.n_norm[4] = atoi(str_data_temp.c_str());
//
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/*----------------------------------------------------------------------------------------------*/
n_BeginPos = str_data.find_first_not_of(' ', n_EndPos);
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.n_norm[5] = atoi(str_data_temp.c_str());
//
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/*----------------------------------------------------------------------------------------------*/
n_BeginPos = str_data.find_first_not_of(' ', n_EndPos);
n_EndPos = str_data.find_first_of(' ', n_BeginPos);
str_data_temp.assign(str_data, n_BeginPos, n_EndPos-n_BeginPos);
// cout << str_data_temp.c_str() << endl;
msd_temp.n_special = atoi(str_data_temp.c_str());
//
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
vec_msd.push_back(msd_temp);
}

int main()
{
ifstream in("test.txt");
// vec_msd.clear();
while(in.getline(ch, 100))
{
GetData(ch);
}

int i_vec_size;
i_vec_size = vec_msd.size();
cout << "总共期数:" << i_vec_size << endl;

int n_0_9_array[10] = {0};
int n_0_9_array_MaxNotCome[10] = {0};
struct max_no_come
{
int year;
int term;
int number;
int times;
}max_no_come;

max_no_come.number = 0;
max_no_come.times = 0;
max_no_come.year = 0;
max_no_come.term = 0;

int j = 0;
int k = 0;
int i_index;
for(j=0; j<i_vec_size; j++)
{
// cout << vec_msd[j].year <<' ' <<vec_msd[j].term << " "<< vec_msd[j].n_norm[0]<< " "<< vec_msd[j].n_norm[1]<< " "<< vec_msd[j].n_norm[2] << " "<< vec_msd[j].n_norm[3] << " "<< vec_msd[j].n_norm[4] << " "<< vec_msd[j].n_norm[5] << " "<< vec_msd[j].n_special <<endl;
for (k=0; k<10; k++)
{
++n_0_9_array_MaxNotCome[k];
}

for(k=0; k<6; k++)
{
i_index = vec_msd[j].n_norm[k]%10;
++n_0_9_array[i_index];
n_0_9_array_MaxNotCome[i_index] = 0;
}
i_index = vec_msd[j].n_special%10;
++n_0_9_array[i_index];
n_0_9_array_MaxNotCome[i_index] = 0;


for (k=0; k<10; k++)
{
if (n_0_9_array_MaxNotCome[k] > max_no_come.times)
{
max_no_come.times = n_0_9_array_MaxNotCome[k];
max_no_come.number = k;/
max_no_come.year = vec_msd[j].year;
max_no_come.term = vec_msd[j].term;
}
}

} //end of calculate

for(k=0; k<10; k++)
{
cout << "数尾为" << k << "的号码来了:" << n_0_9_array[k] << "次。" <<endl;
}

cout << "数尾为:" << max_no_come.number<<"的号码最多"<< max_no_come.times<<"期没来,发生在"<<max_no_come.year<<"年第"<<max_no_come.term<<"期"<<endl;


return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值