📄 arithmetic2dlg.cpp
字号:
// Arithmetic2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Arithmetic2.h"
#include "Arithmetic2Dlg.h"
#include<time.h>
//using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CArithmetic2Dlg dialog
CArithmetic2Dlg::CArithmetic2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CArithmetic2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CArithmetic2Dlg)
m_tips = _T("");
m_arrayCol =0;
m_arrayIndex = 1;
m_arrayRow =0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CArithmetic2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CArithmetic2Dlg)
DDX_Text(pDX, IDC_EDIT_TIPS, m_tips);
DDX_Text(pDX, IDC_COL, m_arrayCol);
DDX_Text(pDX, IDC_INDEX, m_arrayIndex);
DDX_Text(pDX, IDC_ROW, m_arrayRow);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CArithmetic2Dlg, CDialog)
//{{AFX_MSG_MAP(CArithmetic2Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SUBMIT, OnSubmit)
ON_BN_CLICKED(IDC_INPUTARRAY, OnInputarray)
ON_BN_CLICKED(IDC_RESET, OnReset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CArithmetic2Dlg message handlers
BOOL CArithmetic2Dlg::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
for(int i=1;i<=9;i++)
miniStep[i][i].miniValue=0;
m_tips="Four matrixs have been set inner,such as A1(35*40),A2(40*20),A3(20*10),A4(10*15).View the result,please SUBMIT;Begin another experiment,please RESET.";
m_arrayIndex=5;
UpdateData(false);
myArray[1].row=35;
myArray[1].col=myArray[2].row=40;
myArray[2].col=myArray[3].row=20;
myArray[3].col=myArray[4].row=10;
myArray[4].col=15;
strArray="A1A2A3A4";
return TRUE; // return TRUE unless you set the focus to a control
}
void CArithmetic2Dlg::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 CArithmetic2Dlg::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 CArithmetic2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CArithmetic2Dlg::OnInputarray()
{
// TODO: Add your control notification handler code here
CString strFormat,dispArray;
/* if(m_arrayIndex==1)
{
m_tips="";
UpdateData(false);
}*/
UpdateData();
myArray[m_arrayIndex].row=m_arrayRow;
myArray[m_arrayIndex].col=m_arrayCol;
strFormat.Format("A%d",m_arrayIndex);
dispArray.Format("%s",strFormat);
m_tips+=dispArray;
strArray=m_tips;
m_arrayIndex++;
if(m_arrayIndex>=10)
{
m_tips="输入矩阵个数越界!";
m_arrayIndex=9;
}
UpdateData(false);
}
void CArithmetic2Dlg::OnSubmit()
{
// TODO: Add your control notification handler code here
int temp;
m_tips="";
UpdateData();
CString strTag;
clock_t begin,end;
//BEGIN TO CAlCULATE THE TIME COSTING
begin=clock();
//==============================递推过程==============================================
for(int j=2;j<m_arrayIndex;j++)
for(int i=j-1;i>0;i--)
{
for(int k=i;k<j;k++)
{
if(k==i)
{
miniStep[i][j].miniValue=temp=myArray[i].row*myArray[k].col*myArray[j].col
+miniStep[i][k].miniValue+miniStep[k+1][j].miniValue;
miniStep[i][j].minifront=k;
}
else
{
temp=0;
temp=myArray[i].row*myArray[k].col*myArray[j].col+
miniStep[i][k].miniValue+miniStep[k+1][j].miniValue;
if(miniStep[i][j].miniValue>temp)
{
miniStep[i][j].miniValue=temp;
miniStep[i][j].minifront=k;
}
}
}
}
UpdateData(false);
//===============================回归过程==========================================
Regression(1,m_arrayIndex-1);
//END CALCULATING TIME
end=clock();
m_tips.Format("Operating succeed! Wasting time :%fSec. The minimum step of multiple :%d. Result as:",
(double)(end-begin)/CLOCKS_PER_SEC,miniStep[1][m_arrayIndex-1].miniValue);
m_tips+=strArray;
// m_tips.Format("%d,%d",miniStep[1][4].minifront,miniStep[1][4].miniValue);
UpdateData(false);
}
void CArithmetic2Dlg::Regression(int i,int j)
{
int position;
CString strTag,temp;
if(miniStep[i][j].minifront!=i)
{
temp.Format("%d",i);
position=strArray.Find(temp);
// position=strArray.Find(char(i));
strArray.Insert(position-1,'(');
temp.Format("%d",miniStep[i][j].minifront);
position=strArray.Find(temp);
strArray.Insert(position+1,')');
strArray+=strTag;
}
if(miniStep[i][j].minifront+1!=j)
{
temp.Format("%d",miniStep[i][j].minifront+1);
position=strArray.Find(temp);
strArray.Insert(position-1,'(');
temp.Format("%d",j);
position=strArray.Find(temp);
strArray.Insert(position+1,')');
}
//递归调用,插入优先级更高的括号
if(i<miniStep[i][j].minifront-1)
Regression(i,miniStep[i][j].minifront);
if(miniStep[i][j].minifront+1<j-1)
Regression(miniStep[i][j].minifront+1,j);
}
CAsyncSocket
void CArithmetic2Dlg::OnReset()
{
// TODO: Add your control notification handler code here
m_arrayIndex=1;
m_tips="";
// m_tips="Data has been reset,now input new matrixs,make sure the number of matrixs smaller than 9.";
UpdateData(false);
//ENABLE INPUT ITEM
CEdit* pRow=(CEdit*)GetDlgItem(IDC_ROW);
pRow->EnableWindow();
CEdit* pCol=(CEdit*)GetDlgItem(IDC_COL);
pCol->EnableWindow();
CButton* pInput=(CButton*)GetDlgItem(IDC_INPUTARRAY);
pInput->EnableWindow();
//FOCUS ON INPUT IDC_ROW
pRow->SetFocus();
pRow->SetSel(0,-1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -