練習用です。いろんなものがごちゃまぜです。
@@ -0,0 +1,89 @@ | ||
1 | +Public Class CoinsSet | |
2 | + Public Shared typeMaxNum() As Integer = {4, 1, 4, 1, 4, 1, 1} | |
3 | + Public Shared CoinValue() As Integer = {1, 5, 10, 50, 100, 500, 1000} | |
4 | + Private CoinNum(CoinValue.Count - 1) As Integer | |
5 | + | |
6 | + Public Shared Function TypeCount() As Integer | |
7 | + Return CoinValue.Count | |
8 | + End Function | |
9 | + | |
10 | + | |
11 | + Public Sub New(nums As Integer()) | |
12 | + For i As Integer = 0 To CoinNum.Count - 1 | |
13 | + Me.CoinNum(i) = nums(i) | |
14 | + Next | |
15 | + End Sub | |
16 | + | |
17 | + Public Function Value() As Integer | |
18 | + Dim v = 0 | |
19 | + For i As Integer = 0 To CoinNum.Count - 1 | |
20 | + v += CoinNum(i) * CoinValue(i) | |
21 | + Next | |
22 | + Return v | |
23 | + End Function | |
24 | + | |
25 | + Public Shared Function GetMaxCoins() As CoinsSet | |
26 | + Dim instance As New CoinsSet(typeMaxNum) | |
27 | + Return instance | |
28 | + End Function | |
29 | + | |
30 | + Public Function GetClone() As CoinsSet | |
31 | + Dim instance As New CoinsSet(Me.CoinNum) | |
32 | + Return instance | |
33 | + End Function | |
34 | + | |
35 | + Public Function isZero() As Boolean | |
36 | + For Each c In Me.CoinNum | |
37 | + If c <> 0 Then | |
38 | + Return False | |
39 | + End If | |
40 | + Next | |
41 | + Return True | |
42 | + End Function | |
43 | + | |
44 | + Public Sub dec() | |
45 | + For i As Integer = 0 To typeMaxNum.Count - 1 | |
46 | + If 0 < Me.CoinNum(i) Then | |
47 | + Me.CoinNum(i) -= 1 | |
48 | + For j = 0 To i - 1 | |
49 | + Me.CoinNum(j) = typeMaxNum(j) | |
50 | + Next | |
51 | + Exit For | |
52 | + End If | |
53 | + Next | |
54 | + End Sub | |
55 | + | |
56 | + Public Sub DecKeta() | |
57 | + For i As Integer = 0 To typeMaxNum.Count - 1 | |
58 | + If 0 < Me.CoinNum(i) Then | |
59 | + Me.CoinNum(i) = 0 | |
60 | + For j = 0 To i - 1 | |
61 | + Me.CoinNum(j) = typeMaxNum(j) | |
62 | + Next | |
63 | + Exit For | |
64 | + End If | |
65 | + Next | |
66 | + End Sub | |
67 | + | |
68 | + Public Function subs(ByVal cs As CoinsSet) As CoinsSet | |
69 | + Dim instance = Me.GetClone() | |
70 | + For i = 0 To instance.CoinNum.Count - 1 | |
71 | + instance.CoinNum(i) -= cs.CoinNum(i) | |
72 | + Next | |
73 | + Return instance | |
74 | + End Function | |
75 | + | |
76 | + | |
77 | + Public Sub DispUse() | |
78 | + For i = 0 To typeMaxNum.Count - 1 | |
79 | + Console.Write(Me.CoinNum(i)) | |
80 | + Console.Write(" ") | |
81 | + Next | |
82 | + Console.WriteLine() | |
83 | + End Sub | |
84 | + | |
85 | + Public Function CoinSumNum() As Integer | |
86 | + Return CoinNum.Sum() | |
87 | + End Function | |
88 | + | |
89 | +End Class |
@@ -0,0 +1,23 @@ | ||
1 | +Public Class Generator | |
2 | + | |
3 | + Sub generate() | |
4 | + Dim useCoin = CoinsSet.GetMaxCoins | |
5 | + While Not useCoin.isZero() | |
6 | + | |
7 | + Dim moneyCoin = useCoin.GetClone | |
8 | + While Not moneyCoin.isZero() | |
9 | + Dim chargeCoin = useCoin.subs(moneyCoin) | |
10 | + Dim mcPair = New MoneyChangePair(moneyCoin, chargeCoin) | |
11 | + Register.GetInstance.Regist(mcPair) | |
12 | + moneyCoin.DecKeta() | |
13 | + | |
14 | + End While | |
15 | + | |
16 | + useCoin.dec() | |
17 | + End While | |
18 | + | |
19 | + | |
20 | + End Sub | |
21 | + | |
22 | + | |
23 | +End Class |
@@ -0,0 +1,9 @@ | ||
1 | +Module Module1 | |
2 | + | |
3 | + Sub Main() | |
4 | + Dim g As New Generator | |
5 | + g.generate() | |
6 | + Register.GetInstance.Disp() | |
7 | + End Sub | |
8 | + | |
9 | +End Module |
@@ -0,0 +1,17 @@ | ||
1 | +Public Class MoneyChangePair | |
2 | + Private money As CoinsSet | |
3 | + Private change As CoinsSet | |
4 | + Public Sub New(money As CoinsSet, change As CoinsSet) | |
5 | + Me.money = money | |
6 | + Me.change = change | |
7 | + End Sub | |
8 | + | |
9 | + Public Function Value() As Integer | |
10 | + Return money.Value - change.Value | |
11 | + End Function | |
12 | + | |
13 | + Public Function CoinSumNum() As Integer | |
14 | + Return money.CoinSumNum + change.CoinSumNum | |
15 | + End Function | |
16 | + | |
17 | +End Class |
@@ -0,0 +1,13 @@ | ||
1 | +'------------------------------------------------------------------------------ | |
2 | +' <auto-generated> | |
3 | +' This code was generated by a tool. | |
4 | +' Runtime Version:4.0.30319.42000 | |
5 | +' | |
6 | +' Changes to this file may cause incorrect behavior and will be lost if | |
7 | +' the code is regenerated. | |
8 | +' </auto-generated> | |
9 | +'------------------------------------------------------------------------------ | |
10 | + | |
11 | +Option Strict On | |
12 | +Option Explicit On | |
13 | + |
@@ -0,0 +1,35 @@ | ||
1 | +Imports System | |
2 | +Imports System.Reflection | |
3 | +Imports System.Runtime.InteropServices | |
4 | + | |
5 | +' アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 | |
6 | +' アセンブリに関連付けられている情報を変更するには、 | |
7 | +' これらの属性値を変更してください。 | |
8 | + | |
9 | +' アセンブリ属性の値を確認します | |
10 | + | |
11 | +<Assembly: AssemblyTitle("MaxCoins")> | |
12 | +<Assembly: AssemblyDescription("")> | |
13 | +<Assembly: AssemblyCompany("")> | |
14 | +<Assembly: AssemblyProduct("MaxCoins")> | |
15 | +<Assembly: AssemblyCopyright("Copyright © 2018")> | |
16 | +<Assembly: AssemblyTrademark("")> | |
17 | + | |
18 | +<Assembly: ComVisible(False)> | |
19 | + | |
20 | +'このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります | |
21 | +<Assembly: Guid("9884d58f-12db-44bb-8459-a21ee3bb133a")> | |
22 | + | |
23 | +' アセンブリのバージョン情報は次の 4 つの値で構成されています: | |
24 | +' | |
25 | +' メジャー バージョン | |
26 | +' マイナー バージョン | |
27 | +' ビルド番号 | |
28 | +' Revision | |
29 | +' | |
30 | +' すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます | |
31 | +' 既定値にすることができます: | |
32 | +' <Assembly: AssemblyVersion("1.0.*")> | |
33 | + | |
34 | +<Assembly: AssemblyVersion("1.0.0.0")> | |
35 | +<Assembly: AssemblyFileVersion("1.0.0.0")> |
@@ -0,0 +1,62 @@ | ||
1 | +'------------------------------------------------------------------------------ | |
2 | +' <auto-generated> | |
3 | +' This code was generated by a tool. | |
4 | +' Runtime Version:4.0.30319.42000 | |
5 | +' | |
6 | +' Changes to this file may cause incorrect behavior and will be lost if | |
7 | +' the code is regenerated. | |
8 | +' </auto-generated> | |
9 | +'------------------------------------------------------------------------------ | |
10 | + | |
11 | +Option Strict On | |
12 | +Option Explicit On | |
13 | + | |
14 | + | |
15 | +Namespace My.Resources | |
16 | + | |
17 | + 'This class was auto-generated by the StronglyTypedResourceBuilder | |
18 | + 'class via a tool like ResGen or Visual Studio. | |
19 | + 'To add or remove a member, edit your .ResX file then rerun ResGen | |
20 | + 'with the /str option, or rebuild your VS project. | |
21 | + '''<summary> | |
22 | + ''' A strongly-typed resource class, for looking up localized strings, etc. | |
23 | + '''</summary> | |
24 | + <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _ | |
25 | + Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _ | |
26 | + Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ | |
27 | + Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _ | |
28 | + Friend Module Resources | |
29 | + | |
30 | + Private resourceMan As Global.System.Resources.ResourceManager | |
31 | + | |
32 | + Private resourceCulture As Global.System.Globalization.CultureInfo | |
33 | + | |
34 | + '''<summary> | |
35 | + ''' Returns the cached ResourceManager instance used by this class. | |
36 | + '''</summary> | |
37 | + <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ | |
38 | + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager | |
39 | + Get | |
40 | + If Object.ReferenceEquals(resourceMan, Nothing) Then | |
41 | + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("MaxCoins.Resources", GetType(Resources).Assembly) | |
42 | + resourceMan = temp | |
43 | + End If | |
44 | + Return resourceMan | |
45 | + End Get | |
46 | + End Property | |
47 | + | |
48 | + '''<summary> | |
49 | + ''' Overrides the current thread's CurrentUICulture property for all | |
50 | + ''' resource lookups using this strongly typed resource class. | |
51 | + '''</summary> | |
52 | + <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ | |
53 | + Friend Property Culture() As Global.System.Globalization.CultureInfo | |
54 | + Get | |
55 | + Return resourceCulture | |
56 | + End Get | |
57 | + Set(ByVal value As Global.System.Globalization.CultureInfo) | |
58 | + resourceCulture = value | |
59 | + End Set | |
60 | + End Property | |
61 | + End Module | |
62 | +End Namespace |
@@ -0,0 +1,73 @@ | ||
1 | +'------------------------------------------------------------------------------ | |
2 | +' <auto-generated> | |
3 | +' This code was generated by a tool. | |
4 | +' Runtime Version:4.0.30319.42000 | |
5 | +' | |
6 | +' Changes to this file may cause incorrect behavior and will be lost if | |
7 | +' the code is regenerated. | |
8 | +' </auto-generated> | |
9 | +'------------------------------------------------------------------------------ | |
10 | + | |
11 | +Option Strict On | |
12 | +Option Explicit On | |
13 | + | |
14 | + | |
15 | +Namespace My | |
16 | + | |
17 | + <Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _ | |
18 | + Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0"), _ | |
19 | + Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ | |
20 | + Partial Friend NotInheritable Class MySettings | |
21 | + Inherits Global.System.Configuration.ApplicationSettingsBase | |
22 | + | |
23 | + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) | |
24 | + | |
25 | +#Region "My.Settings Auto-Save Functionality" | |
26 | +#If _MyType = "WindowsForms" Then | |
27 | + Private Shared addedHandler As Boolean | |
28 | + | |
29 | + Private Shared addedHandlerLockObject As New Object | |
30 | + | |
31 | + <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _ | |
32 | + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) | |
33 | + If My.Application.SaveMySettingsOnExit Then | |
34 | + My.Settings.Save() | |
35 | + End If | |
36 | + End Sub | |
37 | +#End If | |
38 | +#End Region | |
39 | + | |
40 | + Public Shared ReadOnly Property [Default]() As MySettings | |
41 | + Get | |
42 | + | |
43 | +#If _MyType = "WindowsForms" Then | |
44 | + If Not addedHandler Then | |
45 | + SyncLock addedHandlerLockObject | |
46 | + If Not addedHandler Then | |
47 | + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings | |
48 | + addedHandler = True | |
49 | + End If | |
50 | + End SyncLock | |
51 | + End If | |
52 | +#End If | |
53 | + Return defaultInstance | |
54 | + End Get | |
55 | + End Property | |
56 | + End Class | |
57 | +End Namespace | |
58 | + | |
59 | +Namespace My | |
60 | + | |
61 | + <Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _ | |
62 | + Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _ | |
63 | + Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _ | |
64 | + Friend Module MySettingsProperty | |
65 | + | |
66 | + <Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _ | |
67 | + Friend ReadOnly Property Settings() As Global.MaxCoins.My.MySettings | |
68 | + Get | |
69 | + Return Global.MaxCoins.My.MySettings.Default | |
70 | + End Get | |
71 | + End Property | |
72 | + End Module | |
73 | +End Namespace |
@@ -0,0 +1,38 @@ | ||
1 | +Public Class Register | |
2 | + | |
3 | + Dim dic As New Dictionary(Of Integer, MoneyChangePair) | |
4 | + | |
5 | + Private Shared instance As New Register | |
6 | + Public Shared Function GetInstance() As Register | |
7 | + Return instance | |
8 | + End Function | |
9 | + | |
10 | + Sub Regist(ByVal mcPair As MoneyChangePair) | |
11 | + If mcPair.Value < 0 Then | |
12 | + Exit Sub | |
13 | + End If | |
14 | + Dim key As Integer = mcPair.Value | |
15 | + | |
16 | + If Not dic.ContainsKey(key) Then | |
17 | + 'なければ追加 | |
18 | + dic(key) = mcPair | |
19 | + Else | |
20 | + 'コインの枚数が小さければ更新 | |
21 | + Dim coinNum = dic(key).CoinSumNum | |
22 | + If mcPair.CoinSumNum < coinNum Then | |
23 | + dic(key) = mcPair | |
24 | + End If | |
25 | + End If | |
26 | + End Sub | |
27 | + | |
28 | + Sub Disp() | |
29 | + For Each p In dic | |
30 | + Console.Write(p.Key) | |
31 | + Console.Write(",") | |
32 | + Console.Write(p.Value.CoinSumNum) | |
33 | + Console.WriteLine() | |
34 | + Next | |
35 | + End Sub | |
36 | + | |
37 | + | |
38 | +End Class |