⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 max.cpp

📁 这是我的中文信息处理的小作业
💻 CPP
字号:
// MAX.cpp : implementation file
//

#include "stdafx.h"
#include "DICTIONARY.h"
#include "MAX.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// MAX dialog


MAX::MAX(CWnd* pParent /*=NULL*/)
	: CDialog(MAX::IDD, pParent)
{
	//{{AFX_DATA_INIT(MAX)
	m_maxl = 0;
	//}}AFX_DATA_INIT
}


void MAX::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(MAX)
	DDX_Control(pDX, IDC_EDIT6, m_output4);
	DDX_Control(pDX, IDC_EDIT5, m_output3);
	DDX_Control(pDX, IDC_EDIT4, m_output2);
	DDX_Control(pDX, IDC_EDIT2, m_output);
	DDX_Control(pDX, IDC_EDIT1, m_input);
	DDX_Text(pDX, IDC_EDIT3, m_maxl);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(MAX, CDialog)
	//{{AFX_MSG_MAP(MAX)
	ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// MAX message handlers

bool MAX::Match(CString str)
{	CString word;
	while(file.ReadString(word))
		if(str==word) 
			return TRUE;
	return FALSE;
}

void MAX::ZXMax()
{CString str;
	int i,j;
	str=Sentence;
	j=0;
	while(j<=Count-2)//从0开始算的,一个汉字等于两个字符
	{
		if(Count-j<maxbyte) i=Count-j;
			else i=maxbyte; 
		while(i>2)//多于一个字
		{
			str=Sentence;
			str=str.Mid(j,i);//从j取i个字符 
			file.SeekToBegin();
			if(Match(str))
			{
				m_output.ReplaceSel(str+_T("  "));
				j+=i;
				break;
			}
			else i=i-2;//指针往后移
		}
		if(i==2)//只有一个字
		{
			str=Sentence;
			str=str.Mid(j,i);
			m_output.ReplaceSel(str+_T("  "));
			j+=i;
		}
	}
}

BOOL MAX::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_input.SetWindowText(_T(""));
	m_output.SetWindowText(_T(""));
	m_output2.SetWindowText(_T(""));
	m_output3.SetWindowText(_T(""));
	m_output4.SetWindowText(_T(""));
	m_maxl=4;
	UpdateData(false);	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void MAX::OnOK() 
{
	// TODO: Add extra validation here
	//	file.Open(_T("c:\\DICTIONARY\\ks.txt"),CFile::modeRead
	//	 |CFile::shareDenyNone);
	CHAR  bufferpath[MAX_PATH];
    GetModuleFileName(AfxGetInstanceHandle(),bufferpath,MAX_PATH);
    CString path=bufferpath;
    path = path.Mid(0,path.ReverseFind('\\')+1);
	file.Open(_T(path+"ks.txt"),CFile::modeRead
			 |CFile::shareDenyNone);
	Count=m_input.LineLength(0);//字符个数
	m_input.GetLine(0,Sentence,Count);//给Sentence
	UpdateData(TRUE);
	maxbyte=2*m_maxl;
	ZXMax();
	//CDialog::OnOK();
}

void MAX::OnButtonClear() 
{
	// TODO: Add your control notification handler code here
	m_input.SetWindowText(_T(""));
	m_output.SetWindowText(_T(""));
	m_output2.SetWindowText(_T(""));
	m_output3.SetWindowText(_T(""));
	m_output4.SetWindowText(_T(""));
}

void MAX::OnButton1() 
{
	// TODO: Add your control notification handler code here
    //file.Open(_T("c:\\DICTIONARY\\ks.txt"),CFile::modeRead
	//	 |CFile::shareDenyNone);
    CHAR  bufferpath[MAX_PATH];
    GetModuleFileName(AfxGetInstanceHandle(),bufferpath,MAX_PATH);
    CString path=bufferpath;
    path = path.Mid(0,path.ReverseFind('\\')+1);
	file.Open(_T(path+"ks.txt"),CFile::modeRead
			 |CFile::shareDenyNone);
	Count=m_input.LineLength(0);//字符个数
	m_input.GetLine(0,Sentence,Count);//给Sentence
	UpdateData(TRUE);
	maxbyte=2*m_maxl;
	ZXMin();	
}

void MAX::ZXMin()
{CString str;
 int i,j,stop;
 str=Sentence;
 j=0;
 while(j<=Count-2)
 {        if(Count-j<4) 
               {str=Sentence;
	            str=str.Mid(j,2);
                m_output2.ReplaceSel(str+_T("  "));
                j+=2;
                break;
               }
          if(Count-j>=4&&Count-j<maxbyte)
               {stop=Count-j;i=4;}
          if(Count-j>=maxbyte)
               {stop=maxbyte;i=4;}
          while(i<=stop)
		             {str=Sentence;
                      str=str.Mid(j,i);
                      file.SeekToBegin();
                       if(Match(str))
                            {m_output2.ReplaceSel(str+_T("  "));
                             j+=i;
                             break;
					        }
                       else i=i+2;
                      }
          if(i==stop+2)
            {str=Sentence;
             str=str.Mid(j,2);
             m_output2.ReplaceSel(str+_T("  "));
             j+=2;
            }
 }
}

void MAX::OnButton2() 
{
	// TODO: Add your control notification handler code here
	   // file.Open(_T("c:\\DICTIONARY\\ks.txt"),CFile::modeRead
		 //|CFile::shareDenyNone);
	CHAR  bufferpath[MAX_PATH];
    GetModuleFileName(AfxGetInstanceHandle(),bufferpath,MAX_PATH);
    CString path=bufferpath;
    path = path.Mid(0,path.ReverseFind('\\')+1);
	file.Open(_T(path+"ks.txt"),CFile::modeRead
			 |CFile::shareDenyNone);
	Count=m_input.LineLength(0);//字符个数
	m_input.GetLine(0,Sentence,Count);//给Sentence
	UpdateData(TRUE);
	maxbyte=2*m_maxl;
	NXMax();	
}

void MAX::NXMax()
{CString str;
 str=Sentence;
 int i,j,k,h,r;
 struct Lian*L,*p;
 L=(struct Lian*)malloc(sizeof(struct Lian));
 L->next=NULL;
 j=Count-1;
 while(j>=1)
         {if(j>=maxbyte-1)  i=maxbyte;
           else i=j+1;
		   while(i>2)
		        {str=Sentence;
		         k=j-i+1;
			     str=str.Mid(k,i);
			     file.SeekToBegin();
			     if(Match(str))
				     {//m_output3.ReplaceSel(str+_T(" "));
					  p=(struct Lian*)malloc(sizeof(struct Lian));
					  p->head=k;
					  p->rear=i;
					  p->next=L->next;
                      L->next=p;
					  //h=L->next->head;
					  //r=L->next->rear;
					  //str=Sentence;
					  //str=str.Mid(h,r);
					  //m_output3.ReplaceSel(str+_T(" ")); 

			          j=j-i;
				      break;
			         }
			     else i=i-2;
                }
		   if(i==2)
		        {str=Sentence;
		         k=j-i+1;
		         //str=str.Mid(k,i);
				 //m_output3.ReplaceSel(str+_T(" "));
				 p=(struct Lian*)malloc(sizeof(struct Lian));
				 p->head=k;
		    	 p->rear=i;
				 p->next=L->next;
                 L->next=p;
				 j=j-i;
		        }
           }  
 p=L->next;
 while(p!=NULL)
 {
  h=p->head;
  r=p->rear;
  str=Sentence;
  str=str.Mid(h,r);
  m_output3.ReplaceSel(str+_T("  "));
  p=p->next;
 }
}

void MAX::OnButton3() 
{
	// TODO: Add your control notification handler code here
		   // file.Open(_T("c:\\DICTIONARY\\ks.txt"),CFile::modeRead
		 //|CFile::shareDenyNone);
	CHAR  bufferpath[MAX_PATH];
    GetModuleFileName(AfxGetInstanceHandle(),bufferpath,MAX_PATH);
    CString path=bufferpath;
    path = path.Mid(0,path.ReverseFind('\\')+1);
	file.Open(_T(path+"ks.txt"),CFile::modeRead
			 |CFile::shareDenyNone);
	Count=m_input.LineLength(0);//字符个数
	m_input.GetLine(0,Sentence,Count);//给Sentence
	UpdateData(TRUE);
	maxbyte=2*m_maxl;
	NXMin();	
}



void MAX::NXMin()
{CString str;
 int i,j,k,stop,h,r;
 str=Sentence;
 struct Lian*L,*p;
 L=(struct Lian*)malloc(sizeof(struct Lian));
 L->next=NULL;
 j=Count-1;
 while(j>=1)
 {        if(j<2) 
               {str=Sentence;
                k=j-1;
                p=(struct Lian*)malloc(sizeof(struct Lian));
				p->head=k;
			    p->rear=2;
				p->next=L->next;
                L->next=p;
	            //str=str.Mid(k,2);
                //m_output4.ReplaceSel(str+_T(" "));
                j-=2;
                break;
               }
          if(j>=2&&j<maxbyte-1)
               {stop=j+1;i=4;}
          if(j>=maxbyte-1)
               {stop=maxbyte;i=4;}
          while(i<=stop)
		             {str=Sentence;
		              k=j-i+1;
                      str=str.Mid(k,i);
                      file.SeekToBegin();
                       if(Match(str))
                            { p=(struct Lian*)malloc(sizeof(struct Lian));
					          p->head=k;
					          p->rear=i;
					          p->next=L->next;
                              L->next=p;
						     //m_output4.ReplaceSel(str+_T(" "));
                             j-=i;
                             break;
					        }
                       else i=i+2;
                      }
          if(i==stop+2)
            {//str=Sentence;
		     k=j-1;
             //str=str.Mid(k,2);
             //m_output4.ReplaceSel(str+_T(" "));
			  p=(struct Lian*)malloc(sizeof(struct Lian));
			  p->head=k;
			  p->rear=2;
			  p->next=L->next;
              L->next=p;
             j-=2;
            }
 }
 p=L->next;
 while(p!=NULL)
 {
  h=p->head;
  r=p->rear;
  str=Sentence;
  str=str.Mid(h,r);
  m_output4.ReplaceSel(str+_T("  "));
  p=p->next;
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -