본문 바로가기

c++62

C++ ] leetCode 1769 - Minimum Number of Operations to Move All Balls to Each Box You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball. In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes. Return an array answer of size n, where answer[i] is the min.. 2023. 3. 25.
MFC ] 라디오 버튼 그룹 지정하여 사용하기 + 초기값 지정하기 직관적으로 만들기 위해 그룹 박스를 먼저 그려주고 그 위에 라디오 버튼을 만든다. 라디오 버튼을 MOVE, DELAY, PUMP 이렇게 3개를 만들었다. 내가 생성한 컨트롤에는 각 ID마다 #define으로 숫자값이 부여되는데 이건 Resource.h 에 정의되어 있다. 이 값이 1씩 증가해야 그룹지어 사용할 수 있다. Ctrl+D 를 눌러 중간에 끼어드는 값 없이 번호가 순차적으로 부여되었는지 시각적으로 확인할 수도 있다. 각 라디오 버튼의 속성은 아래처럼 설정한다. 라디오 버튼은 그룹 True 부터 시작해서 다음 True를 만나기 전까지 하나의 그룹으로 묶인다. 이렇게 한 그룹으로 묶이면 클래스 마법사에서 확인해봤을 때 그룹의 첫번째 라디오 버튼만 뜨는 것을 확인할 수 있다. -Dlg.h 파일에 체크.. 2022. 9. 13.
MFC ] 슬라이더 컨트롤 사용하기 도구 상자 - Slider Control 생성하고 그 옆에 Edit Control을 만든다. ID는 다음과 같이 변경했다. 에디트 컨트롤 속성의 숫자를 True로 하면 숫자만 입력되게끔 할 수 있다. 슬라이더 컨트롤은 범주 컨트롤로 변수 추가하고 에디트 컨트롤은 값 CString으로 변수를 추가한다. OnInitDialog() 에 다음과 같이 추가한다. BOOL CdeltaControlDlg::OnInitDialog() { //... SliderInit(&m_sliderX); SliderInit(&m_sliderY); SliderInit(&m_sliderZ); m_strX.Format(_T("%d"), 0); m_strY.Format(_T("%d"), 0); m_strZ.Format(_T("%d"), -.. 2022. 9. 10.
C 와 C++ 으로 10진수를 2진수로 변환하여 출력하기 C #include int main() { short n = 0; printf("-32,768~32,767 사이의 정수를 입력하세요: "); scanf("%hd", &n); for(int i=15; i>=0; i--){ printf("%d", (n >> i) & 1 ); if(i%4==0) printf(" "); } return 0; } C++ #include #include using namespace std; int main() { short n = 0; coutn; cout 2022. 9. 1.
STM32 ] ADC + MFC + MySQL, 시리얼 통신 및 DB연동, 검색기능, 실시간 그래프 구현 (쓰레드 사용) 깃허브 주소 : https://github.com/joeteo/MfcDbAdc GitHub - joeteo/MfcDbAdc Contribute to joeteo/MfcDbAdc development by creating an account on GitHub. github.com https://github.com/joeteo/AdcMfcDb.git GitHub - joeteo/AdcMfcDb Contribute to joeteo/AdcMfcDb development by creating an account on GitHub. github.com 핀설정 가변저항의 VCC, GND는 보드의 +3.3v, GND 에 연결 OUT핀은 아래 ADC 핀에 연결 ADC 설정. DMA 모드를 사용하였다. STM32 whi.. 2022. 7. 17.
MFC ] 실시간 그래프 그리는 법 Real-Time-Chart sin, cos, tan 그래프를 10ms 마다 그리는 예제파일 다이얼로그의 Picture Control을 아이디 IDC_STATIC_RT_GRAPH 로 추가하고 위치와 크기를 맞춘다. 다이얼로그의 -Dlg.h 파일에서 OScopeCtrl.h 파일을 include 하고 COScopeCtrl 컨트롤의 객체 포인터 _rtGraph를 선언해 둔다. // COScopeCtrl의 헤더 파일 인클루드 #include "OScopeCtrl.h" ... class *Dlg : public CDialog { ... // COScopeCtrl 컨트롤의 객체 포인터를 선언 COScopeCtrl *_rtGraph; ... }; onInitDialog() 함수에서는 IDC_STATIC_RT_GRAPH 컨트롤의 위치와 크기를 얻.. 2022. 7. 17.
MFC ] 다이얼로그 종료시 함수 호출 순서 OnClose, OnDestory, PostNcDestroy X 버튼을 눌러서 다이얼로그를 종료한경우 OnSysCommand start OnClose OnSysCommand end DestroyWindow start OnDestroy DestroyWindow end OnNcDestroy start PostNcDestroy OnNcDestroy end EndDialog(), OnOk(), OnCancel() 등을 이용하여 다이얼로그를 종료한경우 DestroyWindow start OnDestroy DestroyWindow end OnNcDestroy start PostNcDestroy OnNcDestroy end 출처 : https://wendys.tistory.com/117 보다시피 WM_CLOSE 메시지의 핸들러인 OnClose()는 EndDialog(), On.. 2022. 7. 15.
MFC ] stringstream 사용하여 문자열 파싱하기 예제코드 CString result; string str = CT2CA(result); istringstream ss(str); string line; int i = 0; while(getline(ss, line, '\n')) { istringstream linestream(line); string cell; getline(linestream, cell, ','); m_list.InsertItem(i, cell.c_str()); int j = 0; while (getline(linestream, cell, ',')) { m_list.SetItem(i, j, LVIF_TEXT, cell.c_str(), NULL, NULL, NULL, NULL); j++; } i++; } '\n' 와 ',' 로 구분하는 형.. 2022. 7. 14.
MFC ] char* -> CString , CString -> char* 변환하기 char* -> CString 변환 char* h1 = "hello"; CString h2 = h1; 그냥 대입해주면 된다 = 연산자 오버로딩이 되어있기 때문이다. CString -> char* 변환 방법1 char* h1 = "hello"; CString h2 = h1; CString w1 = _T("world"); char* w2 = LPSTR(LPCTSTR(w1)); 방법2 CString w1 = _T("world"); char* w2 = w1.GetBuffer(0); 2022. 7. 14.
MFC ] 통계자료, 스레드 Thread 를 사용하여 로드하기 깃허브 주소 : https://github.com/joeteo/CarAccidentList.git GitHub - joeteo/CarAccidentList Contribute to joeteo/CarAccidentList development by creating an account on GitHub. github.com 무거운 프로세스나 무한루프로 동작해야할 작업이 있다면 쓰레드를 생성해서 백그라운드로 작업을 넘기면 된다. 이전에 만든 교통사고 통계조사 프로그램에서 시간이 오래 걸릴 수 있는 파일 불러오기 부분을 스레드를 사용한 버전으로 수정하였다. UINT Load(LPVOID LpData) { CCarAccidentListDlg* target = (CCarAccidentListDlg*)(LpData.. 2022. 7. 9.