彩票小工具(可查询历史、增加新数据、产生随机数、历史对比等)

    因为偶是个彩迷,为了方便自己玩彩票,就写了个工具,可以查询历史中奖记录,添加最新中奖号码,产生随机号码以及和历史记录对比等功能,下面介绍一下使用方法:

1、首先是运行截图:


    程序运行后会提示用户选择功能进行操作,有add, compare, query, last, luck, clear, exit 7个命令,分别代表增加新号码,历史对比,历史查询,最近一期,随机产生号码,清空屏幕,退出程序,下面分别介绍几个功能的使用方法。

2、增加新号码


在命令提示栏输入 add 然后回车,接着输入最新一期的年份和号码,每个数字之间用空格隔开,如上图。

3、历史对比


在命令提示栏输入 compare 然后回车,接着输入要对比的号码,每个数字之间用空格隔开,如上图,结果效果图如下:


Prize1代表输入号码能在历史记录中 中1等奖的次数,Prize2,Prize3...依次类推。

4、历史查询


在命令提示栏输入 query 然后回车,接着输入年份和期数,回车即可看到结果。

5、查询最近一期的年份和期号:


在命令提示栏输入 last 然后回车,即可看到结果。

6、随机产生号码:


在命令提示栏输入 luck 然后回车,接着输入机选的份数,回车即可看到结果。

7、清空屏幕


在命令提示栏输入 clear 然后回车,屏幕内容就会被清空,如下图:


8、退出程序:


在命令提示栏输入 exit 然后回车,即可退出程序。


如果有哪位票友用俺的软件中了大奖,别忘了救济一下偶,大笑,让我脱离苦逼的程序猿。


程序下载地址:点击下载



下面附上代码:


// TestCPData.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include "resource.h"

BOOL CheckDelete();
void SetTxtColor( int nFg );
void SortData( BYTE* byData, int nSize );

void DoLuck();
void DoAdd( BYTE* bySrc );
void DoQuery( BYTE* bySrc );
void DoCompare( BYTE* bySrc );
void DoLastestItem( BYTE* bySrc );

int  GetTotal( BYTE* bySrc );
void GetLuckNumbers( int nTimes );
void GetFileData( BYTE* bySrc, int nSize );
void WriteFileData( BYTE* bySrc, int nSize );
void FindPrizeData( BYTE* bySrc, BYTE* byCmp, int nTotal );

int main(int argc, char* argv[])
{
    system( "cls" );

    if ( CheckDelete())
    {
        return 0;
    }

    system( "cls" );

 	BYTE byTmpBuffer[32000] = { 0 };

	GetFileData( byTmpBuffer, 32000 );

	while ( 1 )
	{
        SetTxtColor( FOREGROUND_INTENSITY );

        printf( "---------------------------------------------------------------------------\n" );
        printf( "Command: 'add','compare','query','last','luck','clear' or 'exit': " );

        SetTxtColor( FOREGROUND_GREEN );

		char szCmd[256] = { 0 };

		scanf( "%s", szCmd );

        fflush( stdin );

		if ( !strnicmp( "add", szCmd, 3 ))
		{
			DoAdd( byTmpBuffer );

            break;
		}
		else if ( !strnicmp( "compare", szCmd, 7 ))
		{
			DoCompare( byTmpBuffer );
		}
        else if ( !strnicmp( "clear", szCmd, 5 ))
        {
            system( "cls" );
        }
        else if ( !strnicmp( "query", szCmd, 5 ))
        {
            DoQuery( byTmpBuffer );
        }
        else if ( !strnicmp( "last", szCmd, 4 ))
        {
            DoLastestItem( byTmpBuffer );
        }
        else if ( !strnicmp( "exit", szCmd, 4 ))
        {
            break;
        }
        else if ( !strnicmp( "luck", szCmd, 4 ))
        {
            DoLuck();
        }
        else
        {
            SetTxtColor( FOREGROUND_RED );

            printf( "Invalid command!\n" );
        }
	}

	return 0;
}

int GetTotal( BYTE* bySrc )
{
	int nTotal = 0;

	if ( bySrc )
	{
		short* pData = ( short* )bySrc;

		for ( int i = 0; i < 20; ++i )
		{
			if ( pData[i*2] )
			{
				nTotal += pData[i*2+1];
			}
			else
			{
				break;
			}
		}
	}

	return nTotal;
}

void DoAdd( BYTE* bySrc )
{
    SetTxtColor( FOREGROUND_INTENSITY );

    printf( "Please input the year and data: " );

    SetTxtColor( FOREGROUND_GREEN );

    int nYear = 0;

	BYTE byData[12] = { 0 };
	
	scanf( "%d%d%d%d%d%d%d%d", &nYear, byData, byData + 1, byData + 2, byData + 3,
		   byData + 4, byData + 5, byData + 6 );

	SortData( byData, 6 );

	fflush( stdin );

	if ( bySrc )
	{
		int nTotal = GetTotal( bySrc );

		FindPrizeData( bySrc, byData, nTotal );

		short* pData = ( short* )bySrc;
		
		for ( int i = 0; i < 20; ++i )
		{
			if ( nYear == pData[i*2] )
			{
				++pData[i*2+1];
				break;
			}
		}

		memcpy( bySrc + 80 + nTotal * 7, byData, 7 );

        WriteFileData( bySrc, 32000 );
	}
}

void DoCompare( BYTE* bySrc )
{
    SetTxtColor( FOREGROUND_INTENSITY );

    printf( "Please input the data: " );

	BYTE byData[12] = { 0 };

    SetTxtColor( FOREGROUND_GREEN );
	
	scanf( "%d%d%d%d%d%d%d", byData, byData + 1, byData + 2, byData + 3,
		byData + 4, byData + 5, byData + 6 );
	
	SortData( byData, 6 );

	fflush( stdin );

	FindPrizeData( bySrc, byData, GetTotal( bySrc ));
}

void DoLastestItem( BYTE* bySrc )
{
    if ( bySrc )
    {
        short* pData = ( short* )bySrc;

        int i = 0;

        for ( i = 0; i < 20; ++i )
        {
            if ( !pData[i*2] )
            {
                break;
            }
        }

        SetTxtColor( FOREGROUND_INTENSITY );

        if ( 0 < i && pData[(i-1)*2] )
        {
            printf( "The lastest item is: " );

            SetTxtColor( FOREGROUND_RED );

            printf( "%d  %d\n", pData[(i-1)*2], pData[(i-1)*2+1] );
        }
        else
        {
            SetTxtColor( FOREGROUND_RED );

            printf( "Invalid data!\n" );
        }
    }
}

void DoQuery( BYTE* bySrc )
{
    SetTxtColor( FOREGROUND_INTENSITY );

    printf( "Please input the year and number: " );

    int nYear = 0;
    int nNumber = 0;

    SetTxtColor( FOREGROUND_GREEN );

    scanf( "%d%d", &nYear, &nNumber );

    fflush( stdin );

    if ( bySrc )
    {
        int nTotal = 0;

        short* pData = ( short* )bySrc;

        BOOL bFind = FALSE;

        for ( int i = 0; i < 20; ++i )
        {
            if ( pData[i*2] == nYear )
            {
                if ( nNumber <= pData[i*2+1] )
                {
                    nTotal += nNumber;

                    bFind = TRUE;
                }

                break;
            }
            else if ( pData[i*2] )
            {
                nTotal += pData[i*2+1];
            }
        }

        int nSum = GetTotal( bySrc );

        if ( bFind )
        {
            BYTE* pbyData = bySrc + 80 + ( nTotal - 1 ) * 7;

            SetTxtColor( FOREGROUND_INTENSITY );

            printf( "Query result is: " );

            SetTxtColor( FOREGROUND_RED );

            printf( "%d %d %d %d %d %d %d\n",
                pbyData[0], pbyData[1], pbyData[2], pbyData[3],
                pbyData[4], pbyData[5], pbyData[6] );
        }
        else
        {
            SetTxtColor( FOREGROUND_RED );

            printf( "The item does not exsit!\n" );
        }
    }
}

void FindPrizeData( BYTE* bySrc, BYTE* byCmp, int nTotal )
{
	int nPrize[6] = { 0 };
	
	BYTE* pbyDst = byCmp;
	
	int i = 0;

	for ( i = 0; i < nTotal; ++i )
	{
		BYTE* pbySrc = bySrc + 80 + i * 7;
		
		int nSames = 0;
		
		for ( int l = 0; l < 7; ++l )
		{
			if ( pbyDst[l] == pbySrc[l] )
			{
				++nSames;
			}
		}
		
		if ( 7 == nSames )
		{
			++nPrize[0];
		}
		else if ( 6 == nSames )
		{
			if ( pbyDst[6] == pbySrc[6] )
			{
				++nPrize[2];
			}
			else
			{
				++nPrize[1];
			}
		}
		else if ( 5 == nSames )
		{
			if ( pbyDst[6] == pbySrc[6] )
			{
				++nPrize[3];
			}
		}
		else if ( 4 == nSames )
		{
			if ( pbyDst[6] == pbySrc[6] )
			{
				++nPrize[4];
			}
		}
		else
		{
			if ( pbyDst[6] == pbySrc[6])
			{
				++nPrize[5];
			}
		}
	}

	for ( i = 0; i < 6; ++i )
	{
        SetTxtColor( FOREGROUND_INTENSITY );

		printf( "Prize%d repeat: ", i + 1 );

        SetTxtColor( FOREGROUND_RED );

        printf( "%d \n", nPrize[i] );
	}
}

void SortData( BYTE* byData, int nSize )
{
    for ( int i = 0; i < nSize - 1; ++i )
    {
        for ( int j = i + 1; j < nSize; ++j )
        {
            if ( byData[i] > byData[j] )
            {
                BYTE byTmp = byData[i];

                byData[i] = byData[j];
                byData[j] = byTmp;
            }
        }
    }
}

void SetTxtColor( int nFg )
{
    HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );

    SetConsoleTextAttribute( hConsole, nFg );
}

void GetFileData( BYTE* bySrc, int nSize )
{
    HMODULE hModule = GetModuleHandle( NULL );

    HRSRC hRes = FindResource( hModule, MAKEINTRESOURCE( IDR_DAT1 ), "DAT" );

    if ( hRes )
    {
        HGLOBAL hGlobal = LoadResource( hModule, hRes );

        BYTE* pbyData = ( BYTE* )LockResource( hGlobal );

        memcpy( bySrc, pbyData, nSize );
    }
}

void WriteFileData( BYTE* bySrc, int nSize )
{
    char szFileName[256] = { 0 };

    GetModuleFileName( NULL, szFileName, 256 );

    char szTmpFile[256] = { 0 };

    strcpy( szTmpFile, szFileName );

    char* pszPath = strrchr( szTmpFile, '\\' );

    char* pszNumb = strrchr( pszPath, '_' );

    if ( pszNumb )
    {
        strcpy( pszNumb, ".exe" );
    }
    else
    {
        strcpy( strrchr( pszPath, '.' ), "_.exe" );
    }

    CopyFile( szFileName, szTmpFile, TRUE );

    BOOL bResult = DeleteFile( szFileName );

    HANDLE hInstance = BeginUpdateResource( szTmpFile, FALSE );

    UpdateResource( hInstance, "DAT", MAKEINTRESOURCE( IDR_DAT1 ), 
        MAKELANGID( LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED ), bySrc, nSize );

    EndUpdateResource( hInstance, FALSE );

    WinExec( szTmpFile, SW_SHOW );
}

BOOL CheckDelete()
{
    char szFileName[256] = { 0 };

    GetModuleFileName( NULL, szFileName, 256 );

    char szTmpFile[256] = { 0 };

    strcpy( szTmpFile, szFileName );

    char* pszPath = strrchr( szFileName, '\\' );

    char* pszSignal = strrchr( pszPath, '_' );

    if ( pszSignal )
    {
        Sleep( 1000 );

        strcpy( pszSignal, ".exe" );

        CopyFile( szTmpFile, szFileName, FALSE );

        WinExec( szFileName, SW_SHOW );

        return TRUE;
    }
    else
    {
        strcpy( strrchr( pszPath, '.' ), "_.exe" );

        if ( INVALID_FILE_ATTRIBUTES != GetFileAttributes( szFileName ))
        {
            Sleep( 1000 );

            DeleteFile( szFileName );
        }
    }
    
    return FALSE;
}

void DoLuck()
{
    SetTxtColor( FOREGROUND_INTENSITY );

    printf( "Please input the times you want: " );

    SetTxtColor( FOREGROUND_GREEN );

    int nTimes = 0;

    scanf( "%d", &nTimes );

    fflush( stdin );

    SetTxtColor( FOREGROUND_RED );

    if ( 0 < nTimes && 10 > nTimes )
    {
        GetLuckNumbers( nTimes );
    }
    else
    {
        printf( "Invalid times, it should be (1-10)\n" );
    }
}

void GetLuckNumbers( int nTimes )
{
    int iArrR[33] = { 0 };
    int iArrB[16] = { 0 };
    int iArrD[ 7] = { 0 };

    int iSum = nTimes;

    int i = 0, j = 0, k = 0, l = 0, ll = 0;

    srand( time( NULL ));

    for ( ll = 0; ll < iSum; ++ll )
    {
        memset( iArrR, 0, 132 );
        memset( iArrB, 0, 64  );

        for ( i = 0; i < 36; ++i )
        {
            memset( iArrD, 0, 28 );

            iArrD[0] = rand() % 33;

            ++iArrR[iArrD[0]];

            for ( j = 1; j < 6; ++j )
            {
                iArrD[j] = rand() % 33;

                for ( l = 0; l < j; ++l )
                {
                    if ( iArrD[j] == iArrD[l] )
                    {
                        Sleep( 10 );

                        iArrD[j] = rand() % 33;

                        l = -1;
                        continue;
                    }
                }

                ++iArrR[iArrD[j]];
            }

            Sleep( 10 );

            iArrD[6] = rand() % 16;

            ++iArrB[iArrD[6]];
        }

        int nGoodNumber[6] = { 0 };

        for ( k = 0; k < 6; ++k )
        {
            int nSel = 0;

            for ( i = 1; i < 33; ++i )
            {
                if ( iArrR[i] > iArrR[nSel] )
                {
                    nSel = i;
                }
            }

            nGoodNumber[k] = nSel + 1;
            iArrR[nSel]    = 0;
        }

        int nSel = 0;

        for ( i = 1; i < 16; ++i )
        {
            if ( iArrB[i] > iArrB[nSel] )
            {
                nSel = i;
            }
        }

        SetTxtColor( FOREGROUND_INTENSITY );

        printf( "The luck numbers is: " );

        SetTxtColor( FOREGROUND_RED );

        for ( i = 0; i < 6; ++i )
        {
            printf( "%02d ", nGoodNumber[i] );
        }

        printf( "%02d\n", nSel + 1 );

        Sleep( 20 );
    }
}

    

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页