📄 hash040819dlg.cpp
字号:
// hash040819Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "hash040819.h"
#include "hash040819Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString str0,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16,str17,str18;
int hash[19];
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHash040819Dlg dialog
CHash040819Dlg::CHash040819Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CHash040819Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHash040819Dlg)
m_edit1 = 0;
m_edit15 = 0;
m_edit10 = 0;
m_edit11 = 0;
m_edit12 = 0;
m_edit13 = 0;
m_edit14 = 0;
m_edit16 = 0;
m_edit17 = 0;
m_edit18 = 0;
m_edit19 = 0;
m_edit2 = 0;
m_edit3 = 0;
m_edit4 = 0;
m_edit5 = 0;
m_edit6 = 0;
m_edit7 = 0;
m_edit8 = 0;
m_edit9 = 0;
m_edit20 = 0;
m_edit21 = 0;
m_edit22 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CHash040819Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHash040819Dlg)
DDX_Text(pDX, IDC_EDIT1, m_edit1);
DDX_Text(pDX, IDC_EDIT15, m_edit15);
DDX_Text(pDX, IDC_EDIT10, m_edit10);
DDX_Text(pDX, IDC_EDIT11, m_edit11);
DDX_Text(pDX, IDC_EDIT12, m_edit12);
DDX_Text(pDX, IDC_EDIT13, m_edit13);
DDX_Text(pDX, IDC_EDIT14, m_edit14);
DDX_Text(pDX, IDC_EDIT16, m_edit16);
DDX_Text(pDX, IDC_EDIT17, m_edit17);
DDX_Text(pDX, IDC_EDIT18, m_edit18);
DDX_Text(pDX, IDC_EDIT19, m_edit19);
DDX_Text(pDX, IDC_EDIT2, m_edit2);
DDX_Text(pDX, IDC_EDIT3, m_edit3);
DDX_Text(pDX, IDC_EDIT4, m_edit4);
DDX_Text(pDX, IDC_EDIT5, m_edit5);
DDX_Text(pDX, IDC_EDIT6, m_edit6);
DDX_Text(pDX, IDC_EDIT7, m_edit7);
DDX_Text(pDX, IDC_EDIT8, m_edit8);
DDX_Text(pDX, IDC_EDIT9, m_edit9);
DDX_Text(pDX, IDC_EDIT20, m_edit20);
DDX_Text(pDX, IDC_EDIT21, m_edit21);
DDX_Text(pDX, IDC_EDIT22, m_edit22);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHash040819Dlg, CDialog)
//{{AFX_MSG_MAP(CHash040819Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHash040819Dlg message handlers
BOOL CHash040819Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CHash040819Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CHash040819Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CHash040819Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CHash040819Dlg::OnButton1()
{
int i;
int num[19];
unsigned long int l;
UpdateData();
num[0]=m_edit1;
num[1]=m_edit2;
num[2]=m_edit3;
num[3]=m_edit4;
num[4]=m_edit5;
num[5]=m_edit6;
num[6]=m_edit7;
num[7]=m_edit8;
num[8]=m_edit9;
num[9]=m_edit10;
num[10]=m_edit11;
num[11]=m_edit12;
num[12]=m_edit13;
num[13]=m_edit14;
num[14]=m_edit15;
num[15]=m_edit16;
num[16]=m_edit17;
num[17]=m_edit18;
num[18]=m_edit19;
for(i=0;i<19;i++)
hash[i]=0;
for(i=0;i<19;i++)
{
l=num[i]%19;
if(hash[l]==0)
hash[l]=num[i];
else {
do{l=(l+1)%19;
}while (hash[l]!=0);
hash[l]=num[i];
}
}
str0.Format("%5d",hash[0]);
str1.Format("%5d",hash[1]);
str2.Format("%5d",hash[2]);
str3.Format("%5d",hash[3]);
str4.Format("%5d",hash[4]);
str5.Format("%5d",hash[5]);
str6.Format("%5d",hash[6]);
str7.Format("%5d",hash[7]);
str8.Format("%5d",hash[8]);
str9.Format("%5d",hash[9]);
str10.Format("%5d",hash[10]);
str11.Format("%5d",hash[11]);
str12.Format("%5d",hash[12]);
str13.Format("%5d",hash[13]);
str14.Format("%5d",hash[14]);
str15.Format("%5d",hash[15]);
str16.Format("%5d",hash[16]);
str17.Format("%5d",hash[17]);
str18.Format("%5d",hash[18]);
MessageBox(str0+str1+str2+str3+str4+str5+str6+str7+str8+str9+str10+str11+str12+str13+str14+str15+str16+str17+str18) ;
UpdateData(FALSE);
}
void CHash040819Dlg::OnButton2()
{
unsigned long int l;
int s;
UpdateData();
s=m_edit20;
l=s%19;
if(hash[l]==0)
hash[l]=s;
else {
do{l=(l+1)%19;
}while (hash[l]!=0);
hash[l]=s;
}
str0.Format("%5d",hash[0]);
str1.Format("%5d",hash[1]);
str2.Format("%5d",hash[2]);
str3.Format("%5d",hash[3]);
str4.Format("%5d",hash[4]);
str5.Format("%5d",hash[5]);
str6.Format("%5d",hash[6]);
str7.Format("%5d",hash[7]);
str8.Format("%5d",hash[8]);
str9.Format("%5d",hash[9]);
str10.Format("%5d",hash[10]);
str11.Format("%5d",hash[11]);
str12.Format("%5d",hash[12]);
str13.Format("%5d",hash[13]);
str14.Format("%5d",hash[14]);
str15.Format("%5d",hash[15]);
str16.Format("%5d",hash[16]);
str17.Format("%5d",hash[17]);
str18.Format("%5d",hash[18]);
MessageBox(str0+str1+str2+str3+str4+str5+str6+str7+str8+str9+str10+str11+str12+str13+str14+str15+str16+str17+str18) ;
UpdateData(FALSE);
}
void CHash040819Dlg::OnButton3()
{
unsigned long int l;
int s;
UpdateData();
CString search1;
s=m_edit21;
l=s%19;
if (hash[l]==s)
{ l=l+1;
search1.Format("%d",l);
MessageBox("在第"+search1+"个位置");
return;
}
while((hash[l]!=s)&&(hash[l]!=0) )
l=(l+1)%19;
if (hash[l]==s)
{ l=l+1;
search1.Format("%d",l);
MessageBox("在第"+search1+"个位置");
}
else MessageBox("不存在此数!");
UpdateData(FALSE);
}
void CHash040819Dlg::OnButton4()
{
unsigned long int l;
int k,i,n=0;
int num[19];
UpdateData();
CString search1;
k=m_edit22;
for (i=0;i<19;i++)
{ if (hash[i]==k)
{hash[i]=0;n=1;
}
}
if (n==0)
{MessageBox("不存在此数!");return;
}
else
{for(i=0;i<19;i++)
num[i]=hash[i];
}
for(i=0;i<19;i++)
hash[i]=0;
for(i=0;i<19;i++)
{
l=num[i]%19;
if(hash[l]==0)
hash[l]=num[i];
else {
do{l=(l+1)%19;
}while (hash[l]!=0);
hash[l]=num[i];
}
}
str0.Format("%5d",hash[0]);
str1.Format("%5d",hash[1]);
str2.Format("%5d",hash[2]);
str3.Format("%5d",hash[3]);
str4.Format("%5d",hash[4]);
str5.Format("%5d",hash[5]);
str6.Format("%5d",hash[6]);
str7.Format("%5d",hash[7]);
str8.Format("%5d",hash[8]);
str9.Format("%5d",hash[9]);
str10.Format("%5d",hash[10]);
str11.Format("%5d",hash[11]);
str12.Format("%5d",hash[12]);
str13.Format("%5d",hash[13]);
str14.Format("%5d",hash[14]);
str15.Format("%5d",hash[15]);
str16.Format("%5d",hash[16]);
str17.Format("%5d",hash[17]);
str18.Format("%5d",hash[18]);
MessageBox("删除已成功") ;
UpdateData(FALSE);
}
void CHash040819Dlg::OnButton5()
{
MessageBox("当前哈希表为:"+str0+str1+str2+str3+str4+str5+str6+str7+str8+str9+str10+str11+str12+str13+str14+str15+str16+str17+str18) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -