SudokuSum.zip

  • y_Rezazade
    了解作者
  • C++ Builder
    开发工具
  • 86KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2021-02-10 22:01
    上传日期
a program for find combination of N Number to reach a Sum. this solve sudoku puzzle.
SudokuSum.zip
  • SudokuSum.cbproj
    8KB
  • Unit1.h
    1.4KB
  • SudokuSum.cbproj.local
    1.4KB
  • SudokuSum.res
    90.3KB
  • Unit1.dfm
    1.6KB
  • SudokuSum.cpp
    870B
  • Unit1.cpp
    3.1KB
内容介绍
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzButton" #pragma link "RzEdit" #pragma link "RzLabel" #pragma link "RzSpnEdt" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Incr () { int Loc = DCnt -1; while ( 1 == 1 ) if ( ++ Sums [Loc] > 9 ) { if ( Loc == 0 ) return; Sums [Loc] = Loc; Loc --; } else return; } //--------------------------------------------------------------------------- bool __fastcall TForm1::Calc () { int i, j, S = 0; for ( i = 0; i < DCnt; i ++ ) S += Sums [i]; if ( S != Val ) return false; for ( i = 0; i < DCnt; i ++ ) for ( j = i + 1; j < DCnt; j ++ ) if ( Sums [i] == Sums [j] ) return false; return true; } //--------------------------------------------------------------------------- void __fastcall TForm1::PrintfRes() { AnsiString Vals = ""; for ( int i = 0; i < DCnt; i ++ ) Vals = Vals + IntToStr ( Sums [i] ); Res->Lines->Add ( Vals ); } //--------------------------------------------------------------------------- bool __fastcall TForm1::ChechLines() { int i, j, Same = 0; for ( i = 0; i < Res->Lines->Count; i ++ ) { for ( Same = j = 0; j < DCnt; j ++ ) if ( Res->Lines->Strings [i].Pos(IntToStr ( Sums[j] ) ) > 0 ) Same ++; if ( Same == DCnt ) return false; } return true; } //--------------------------------------------------------------------------- void __fastcall TForm1::CalcBtnClick(TObject *Sender) { int i, Loc; DCnt = Digits->Text.ToIntDef(0); // Digit Count Val = Sum->Text.ToIntDef(0); // Value Res->Lines->Clear (); if ( DCnt <= 1 || DCnt > 9 ) { ShowMessage ( "Are you OK?" ); return; } for ( i = 0; i < DCnt; i ++ ) Sums [i] = i + 1; Sums [0] = 1; while ( Sums [0] < 10 ) { if ( Calc () && ChechLines () ) PrintfRes (); Incr (); } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyPress(TObject *Sender, wchar_t &Key) { if ( Key == VK_RETURN ) SelectNext ( ActiveControl, true, true ); if ( Key == VK_ESCAPE ) SelectFirst (); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if ( Key == VK_F2 ) { CalcBtnClick ( CalcBtn ); SelectFirst (); } } //--------------------------------------------------------------------------- void __fastcall TForm1::CloseBtnClick(TObject *Sender) { Close (); } //---------------------------------------------------------------------------
评论
    相关推荐
    • C++builder
      C++代码开发,简单易用,易安装
    • C++ Builder
      可视化程序设计的讲义,供大家参考学习
    • C++builder
      主要是c++buider程序,适合考试论文使用,主要就是窗体代码
    • C++builder
      关于C++builder 6的一些东西,希望大家会喜欢!谢谢!
    • C++Builder
      c++builder高级应用开发指南完整配套代码
    • c++builder
      基于c++的远程控制代码,鼠标键盘虚拟事件的应用
    • c++ builder 资源
      (1)学会在C++Builder下调试C程序、C++程序; (2)学会在C++Builder的编程环境下编制简单的应用程序; (3)掌握面向对象的程序设计思想; (4)掌握当今流行的C++Builder快速应用程序开发环境; (5)掌握包括...
    • C++Builder
      it's good.
    • C++builder
      学习c++builder的好帮手,助你成为开发高手。
    • C++BUILDER
      经典的游戏 贪吃蛇