📄 testdlg.cpp
字号:
// TestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "01knapsackMFC.h"
#include "TestDlg.h"
#include "KnapSock.h"
#include <time.h>
#include <stdlib.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#define IDCWEIGHT(a) IDC_W0a##
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
srand(time(NULL));
maxWeight = 0;
valueGot = 0;
weightGot = 0;
for (int i = 0; i <= num; i++)
{
value[i] = rand() % 10 + 1;
weight[i] = rand() % 10 + 1;
obj[i] = 0;
}
//}}AFX_DATA_INIT
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Text(pDX, IDC_MAXWEIGHT, maxWeight);
DDX_Text(pDX, IDC_WEIGHTGOT, weightGot);
DDX_Text(pDX, IDC_VALUEGOT, valueGot);
DDX_Text(pDX, IDC_W01, weight[1]);
DDX_Text(pDX, IDC_W02, weight[2]);
DDX_Text(pDX, IDC_W03, weight[3]);
DDX_Text(pDX, IDC_W04, weight[4]);
DDX_Text(pDX, IDC_W05, weight[5]);
DDX_Text(pDX, IDC_W06, weight[6]);
DDX_Text(pDX, IDC_W07, weight[7]);
DDX_Text(pDX, IDC_W08, weight[8]);
DDX_Text(pDX, IDC_W09, weight[9]);
DDX_Text(pDX, IDC_W10, weight[10]);
DDX_Text(pDX, IDC_V01, value[1]);
DDX_Text(pDX, IDC_V02, value[2]);
DDX_Text(pDX, IDC_V03, value[3]);
DDX_Text(pDX, IDC_V04, value[4]);
DDX_Text(pDX, IDC_V05, value[5]);
DDX_Text(pDX, IDC_V06, value[6]);
DDX_Text(pDX, IDC_V07, value[7]);
DDX_Text(pDX, IDC_V08, value[8]);
DDX_Text(pDX, IDC_V09, value[9]);
DDX_Text(pDX, IDC_V10, value[10]);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_BN_CLICKED(IDC_CACULATEBUTTON, OnCaculatebutton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
#define JUDGEMARK(a) if (obj[##a] == 1) GetDlgItem(IDC_CHECK##a)->SetWindowText("1"); \
else GetDlgItem(IDC_CHECK##a)->SetWindowText("0");
void CTestDlg::OnCaculatebutton()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
KnapSock ks(num, maxWeight, weight, value);
ks.FindWay();
valueGot = ks.ValueGot();
ks.Mark(obj);
weightGot = ks.WeightGot();
JUDGEMARK(1)
JUDGEMARK(2)
JUDGEMARK(3)
JUDGEMARK(4)
JUDGEMARK(5)
JUDGEMARK(6)
JUDGEMARK(7)
JUDGEMARK(8)
JUDGEMARK(9)
JUDGEMARK(10)
UpdateData(FALSE);
}
//#JUDGEMARK(a)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -