• 大小: 110KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2022-08-27
  • 语言: C#
  • 标签: C#  

资源简介

找零钱算法 C#实现

资源截图

代码片段和文件信息

using Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_Click( object sender  EventArgs e )
        {
            // 获取输入

            int total = Convert.ToInt32( tbTotal.Text );

            var strs = tbElements.Text.Split( new string[ ] { ““ }  StringSplitOptions.None );
            List elems = new List();
            foreach( var str in strs )
            {
                var n = Convert.ToInt32( str );
                elems.Add( n );
            }

            var num = Convert.ToInt32( tbNumOfSolutions.Text );

            var stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start(); //  开始监视代码运行时间

            tbRet.Text = “正在求解... ...“;

           // 计算
           var ret = MumberDecompose.Decompose( total  elems  num );

            stopwatch.Stop(); //  停止监视
            TimeSpan timespan = stopwatch.Elapsed; //  获取当前实例测量得出的总时间
            var Elapsed = timespan.TotalMilliseconds;

            ShowRet( ret  Elapsed );

        }

        void ShowRet( List> ret   double Elapsed )
        {
            string str = ““;

            str += “耗时:“ + Elapsed.ToString() + “ 毫秒“ + “\r\n \r\n“ ;
            str += “解个数:“ + ret.Count.ToString() + “\r\n \r\n“;

            var sb = new StringBuilder();
            foreach ( var s in ret )
            {
                var sb2 = new StringBuilder();
                foreach ( var e in s )
                {
                    sb2.Append( e );
                    sb2.Append( “ + “ );
                }
                sb2.Remove( sb2.Length - 3  3 );
                sb2.Append( “\r\n“ )  ;

                sb.Append( sb2.ToString() );

            }

            str += sb.ToString();

            tbRet.Text = str;

        }

    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-06-22 11:27  WindowsFormsApplication1\
     目录           0  2017-06-22 11:27  WindowsFormsApplication1\.vs\
     目录           0  2017-06-22 11:27  WindowsFormsApplication1\.vs\WindowsFormsApplication1\
     目录           0  2017-06-22 11:27  WindowsFormsApplication1\.vs\WindowsFormsApplication1\v14\
     文件       53248  2017-06-22 14:02  WindowsFormsApplication1\.vs\WindowsFormsApplication1\v14\.suo
     目录           0  2017-06-22 13:53  WindowsFormsApplication1\WindowsFormsApplication1\
     文件        1039  2017-06-22 11:27  WindowsFormsApplication1\WindowsFormsApplication1.sln
     文件         189  2017-06-22 11:27  WindowsFormsApplication1\WindowsFormsApplication1\App.config
     目录           0  2017-06-22 12:51  WindowsFormsApplication1\WindowsFormsApplication1\bin\
     目录           0  2017-06-22 11:55  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\
     文件       12288  2017-06-22 12:51  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
     文件         189  2017-06-22 11:27  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe.config
     文件       24064  2017-06-22 12:51  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
     文件       22696  2017-06-22 12:51  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
     文件         189  2017-06-22 11:27  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.config
     文件         490  2017-03-19 05:00  WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
     目录           0  2017-06-23 01:30  WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\
     文件       11776  2017-06-23 00:00  WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.exe
     文件         189  2017-06-22 11:27  WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.exe.config
     文件       24064  2017-06-23 00:00  WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.pdb
     文件       22696  2017-06-23 01:29  WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe
     文件         189  2017-06-22 11:27  WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe.config
     文件         490  2017-03-19 05:00  WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe.manifest
     文件        5439  2017-06-23 01:30  WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.zip
     文件        2299  2017-06-22 13:53  WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
     文件        6834  2017-06-22 13:23  WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
     文件        5817  2017-06-22 13:23  WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
     文件        2167  2017-06-22 13:52  WindowsFormsApplication1\WindowsFormsApplication1\MumberDecompose.cs
     目录           0  2017-06-22 12:51  WindowsFormsApplication1\WindowsFormsApplication1\obj\
     目录           0  2017-06-22 12:51  WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\
     文件         868  2017-06-22 11:27  WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此处省略33个文件信息

评论

共有 条评论