Skip to content

Instantly share code, notes, and snippets.

@Sprite105
Created November 26, 2015 09:07
Show Gist options
  • Save Sprite105/b75a3a6eae7fa37d6b0d to your computer and use it in GitHub Desktop.
Save Sprite105/b75a3a6eae7fa37d6b0d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
class Class1
{
private int num;
public void get(int a) {
num = a;
func();
}
private void func() {
int[] mas = { 100, 20, 10, 5, 2, 1 };
int[] mas2 = new int[1000];
int res = 0, j = 0;
for (int i = 0; i < mas.Length; i++ ) {
res += mas[i];
mas2[j] = mas[i]; j++;
if (res == num) break;
if (num > res) {
while (num > res) {
mas2[j] = mas[i]; j++;
res += mas[i];
}
} if (num < res) { res -= mas[i]; j--; }
}
string dot;
for (int k = 0; k < j; k++) {
if ((k + 1) == j) { dot = ""; } else { dot = ","; }
Console.Write(mas2[k] + dot);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment