using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharpProject {
/// <summary>
/// 単なる数値で表された金額を硬貨、札で表現しなおすクラス。
/// </summary>
public class Mony {
//内部用の機械的アクセス用。
private int[] datas = new int[9];
public int One { get { return datas[0]; } private set { datas[0] = value; } }
public int Five { get { return datas[1]; } private set { datas[1] = value; } }
//10
public int Ten { get { return datas[2]; } private set { datas[2] = value; } }
public int Fifty { get { return datas[3]; } private set { datas[3] = value; } }
public int Hundred { get { return datas[4]; } private set { datas[4] = value; } }
public int FiveHundred { get { return datas[5]; } private set { datas[5] = value; } }
//1,000
public int Thousand { get { return datas[6]; } private set { datas[6] = value; } }
public int FiveThousand { get { return datas[7]; } private set { datas[7] = value; } }
//10,000
public int TehThousand { get { return datas[8]; } private set { datas[8] = value; } }
private int intValue;
/// <summary>
/// このクラスを初期化します。
/// </summary>
/// <param name="value">金額</param>
public Mony(int value) {
ParseInt(value);
}
/// <summary>
/// intをパースしてMonyクラスにセットする
/// </summary>
/// <param name="num"></param>
private void ParseInt(int num) {
//Array.Clear(datas, 0, datas.Length);
intValue = num;
for (int i = 1; i <= Math.Min(4, (int)Math.Log10(num) + 1); i++) {
var value = GetDigitValue(num, i);
if (value >= 5) {
datas[(i - 1) * 2] = value - 5;
datas[(i - 1) * 2 + 1]++;
} else {
datas[(i - 1) * 2] = value;
}
}
TehThousand = num / 10000;
}
/// <summary>
/// intの任意の桁の値を取得します。
/// </summary>
/// <param name="digit">下から数えた取得したい桁数</param>
/// <param name="num">取得する元の数値</param>
private int GetDigitValue(int num, int digit) {
int numDighit = (int)Math.Log10(num) + 1;
if (numDighit < digit || digit < 0)
throw new ArgumentException("digit");
for (int i = numDighit; i > digit; i--) {
//消去したい桁数
int deleateDigiht = (int)Math.Pow(10, (int)Math.Log10(num));
//ex:4321→4→4000
num -= num / deleateDigiht * deleateDigiht;
}
if (digit == 1)
return num;
return num / (int)Math.Pow(10, digit - 1);
}
/// <summary>
/// この構造体をintに変換します。
/// </summary>
/// <returns></returns>
public int ToInt32() {
return intValue;
}
}
class Program {
public static void Main() {
//お釣り
var m = new Mony(1234986);
var s = string.Format("10,000yen>{0},5,000yen>{1},1,000yen>{2},500yen>{3},100yen{4},50yen>{5},10yen>{6},5yen>{7},1yen>{8}",
m.TehThousand, m.FiveThousand, m.Thousand, m.FiveHundred, m.Hundred, m.Fifty,m.Ten, m.Five, m.One);
Console.WriteLine(s);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CgpuYW1lc3BhY2UgQ1NoYXJwUHJvamVjdCB7CiAgICAvLy8gPHN1bW1hcnk+CiAgICAvLy8g5Y2Y44Gq44KL5pWw5YCk44Gn6KGo44GV44KM44Gf6YeR6aGN44KS56Gs6LKo44CB5pyt44Gn6KGo54++44GX44Gq44GK44GZ44Kv44Op44K544CCCiAgICAvLy8gPC9zdW1tYXJ5PgogICAgcHVibGljIGNsYXNzIE1vbnkgewogICAgICAgIC8v5YaF6YOo55So44Gu5qmf5qKw55qE44Ki44Kv44K744K555So44CCCiAgICAgICAgcHJpdmF0ZSBpbnRbXSBkYXRhcyA9IG5ldyBpbnRbOV07CgogICAgICAgIHB1YmxpYyBpbnQgT25lIHsgZ2V0IHsgcmV0dXJuIGRhdGFzWzBdOyB9IHByaXZhdGUgc2V0IHsgZGF0YXNbMF0gPSB2YWx1ZTsgfSB9CiAgICAgICAgcHVibGljIGludCBGaXZlIHsgZ2V0IHsgcmV0dXJuIGRhdGFzWzFdOyB9IHByaXZhdGUgc2V0IHsgZGF0YXNbMV0gPSB2YWx1ZTsgfSB9CiAgICAgICAgLy8xMAogICAgICAgIHB1YmxpYyBpbnQgVGVuIHsgZ2V0IHsgcmV0dXJuIGRhdGFzWzJdOyB9IHByaXZhdGUgc2V0IHsgZGF0YXNbMl0gPSB2YWx1ZTsgfSB9CiAgICAgICAgcHVibGljIGludCBGaWZ0eSB7IGdldC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ICAgIC8vLyBpbnTjgpLjg5Hjg7zjgrnjgZfjgaZNb25544Kv44Op44K544Gr44K744OD44OI44GZ44KLCiAgICAgICAgLy8vIDwvc3VtbWFyeT4KICAgICAgICAvLy8gPHBhcmFtIG5hbWU9Im51bSI+PC9wYXJhbT4KICAgICAgICBwcml2YXRlIHZvaWQgUGFyc2VJbnQoaW50IG51bSkgewogICAgICAgICAgICAvL0FycmF5LkNsZWFyKGRhdGFzLCAwLCBkYXRhcy5MZW5ndGgpOwogICAgICAgICAgICBpbnRWYWx1ZSA9IG51bTsKCiAgICAgICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IE1hdGguTWluKDQsIChpbnQpTWF0aC5Mb2cxMChudW0pICsgMSk7IGkrKykgewogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gR2V0RGlnaXRWYWx1ZShudW0sIGkpOwogICAgICAgICAgICAgICAgaWYgKHZhbHVlID49IDUpIHsKICAgICAgICAgICAgICAgICAgICBkYXRhc1soaSAtIDEpICogMl0gPSB2YWx1ZSAtIDU7CiAgICAgICAgICAgICAgICAgICAgZGF0YXNbKGkgLSAxKSAqIDIgKyAxXSsrOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBkYXRhc1soaSAtIDEpICogMl0gPSB2YWx1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgVGVoVGhvdXNhbmQgPSBudW0gLyAxMDAwMDsKICAgICAgICB9CgogICAgICAgIC8vLyA8c3VtbWFyeT4KICAgICAgICAvLy8gaW5044Gu5Lu75oSP44Gu5qGB44Gu5YCk44KS5Y+W5b6X44GX44G+44GZ44CCCiAgICAgICAgLy8vIDwvc3VtbWFyeT4KICAgICAgICAvLy8gPHBhcmFtIG5hbWU9ImRpZ2l0Ij7kuIvjgYvjgonmlbDjgYjjgZ/lj5blvpfjgZfjgZ/jgYTmoYHmlbA8L3BhcmFtPgogICAgICAgIC8vLyA8cGFyYW0gbmFtZT0ibnVtIj7lj5blvpfjgZnjgovlhYPjga7mlbDlgKQ8L3BhcmFtPgogICAgICAgIHByaXZhdGUgaW50IEdldERpZ2l0VmFsdWUoaW50IG51bSwgaW50IGRpZ2l0KSB7CiAgICAgICAgICAgIGludCBudW1EaWdoaXQgPSAoaW50KU1hdGguTG9nMTAobnVtKSArIDE7CiAgICAgICAgICAgIGlmIChudW1EaWdoaXQgPCBkaWdpdCB8fCBkaWdpdCA8IDApCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgQXJndW1lbnRFeGNlcHRpb24oImRpZ2l0Iik7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSBudW1EaWdoaXQ7IGkgPiBkaWdpdDsgaS0tKSB7CiAgICAgICAgICAgICAgICAvL+a2iOWOu+OBl+OBn+OBhOahgeaVsAogICAgICAgICAgICAgICAgaW50IGRlbGVhdGVEaWdpaHQgPSAoaW50KU1hdGguUG93KDEwLCAoaW50KU1hdGguTG9nMTAobnVtKSk7CiAgICAgICAgICAgICAgICAvL2V4OjQzMjHihpI04oaSNDAwMAogICAgICAgICAgICAgICAgbnVtIC09IG51bSAvIGRlbGVhdGVEaWdpaHQgKiBkZWxlYXRlRGlnaWh0OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChkaWdpdCA9PSAxKQogICAgICAgICAgICAgICAgcmV0dXJuIG51bTsKICAgICAgICAgICAgcmV0dXJuIG51bSAvIChpbnQpTWF0aC5Qb3coMTAsIGRpZ2l0IC0gMSk7CiAgICAgICAgfQoKICAgICAgICAvLy8gPHN1bW1hcnk+CiAgICAgICAgLy8vIOOBk+OBruani+mAoOS9k+OCkmludOOBq+WkieaPm+OBl+OBvuOBmeOAggogICAgICAgIC8vLyA8L3N1bW1hcnk+CiAgICAgICAgLy8vIDxyZXR1cm5zPjwvcmV0dXJucz4KICAgICAgICBwdWJsaWMgaW50IFRvSW50MzIoKSB7CiAgICAgICAgICAgIHJldHVybiBpbnRWYWx1ZTsKICAgICAgICB9CgogICAgfQoKICAgIGNsYXNzIFByb2dyYW0gewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkgewogICAgICAgICAgICAvL+OBiumHo+OCigogICAgICAgICAgICB2YXIgbSA9IG5ldyBNb255KDEyMzQ5ODYpOwogICAgICAgICAgICB2YXIgcyA9IHN0cmluZy5Gb3JtYXQoIjEwLDAwMHllbj57MH0sNSwwMDB5ZW4+ezF9LDEsMDAweWVuPnsyfSw1MDB5ZW4+ezN9LDEwMHllbns0fSw1MHllbj57NX0sMTB5ZW4+ezZ9LDV5ZW4+ezd9LDF5ZW4+ezh9IiwKICAgICAgICAgICAgICAgIG0uVGVoVGhvdXNhbmQsIG0uRml2ZVRob3VzYW5kLCBtLlRob3VzYW5kLCBtLkZpdmVIdW5kcmVkLCBtLkh1bmRyZWQsIG0uRmlmdHksbS5UZW4sIG0uRml2ZSwgbS5PbmUpOwogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZShzKTsKICAgICAgICB9CiAgICB9Cn0K