Advertisement
Guest User

C# to PY migration needed

a guest
Dec 7th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MigrateToPY
  8. {
  9.     class Program
  10.     {
  11.         public static long count = 0;
  12.        // public static int countOfIterations = 1;
  13.         public static void printAllCents(int ind, int[] denom, int N, int[] vals)
  14.         {
  15.            
  16.             if (N == 0)
  17.             {
  18.                 if (ind < denom.Length)
  19.                 {
  20.                     for (int i = ind; i < denom.Length; i++)
  21.                         vals[i] = 0;
  22.                 }
  23.                 //Console.WriteLine("Kombinacja numer: {0}", countOfIterations);
  24.                 foreach (var c in vals)
  25.                 {
  26.                     //Console.WriteLine(c);
  27.                     count++;
  28.                 }
  29.                 //Console.WriteLine();
  30.                 //countOfIterations++;
  31.                 return;
  32.             }
  33.             if (ind == (denom.Length))
  34.             {
  35.                 vals[ind - 1] = 0;
  36.                 return;
  37.             }
  38.  
  39.             int currdenom = denom[ind];
  40.             for (int i = 0; i <= (N / currdenom); i++)
  41.             {
  42.                 vals[ind] = i;
  43.                 printAllCents(ind + 1, denom, N - i * currdenom, vals);
  44.             }
  45.         }
  46.         static void Main(string[] args)
  47.         {
  48.             int[] denom = { 1, 2, 5, 10, 50 };
  49.             int[] vals = new int[denom.Length];
  50.             int N = 1000;
  51.             //Console.WriteLine("Twoje kombinacje: ");
  52.             printAllCents(0, denom, N, vals);
  53.             Console.WriteLine("Twoja kwota to: {0}", N);
  54.             Console.Write("Twoje liczby to:");
  55.             foreach (var c in denom) Console.Write(c + " ");
  56.             Console.WriteLine();
  57.             Console.WriteLine("Ilosc twoich wynikow to: {0}",count/denom.Length);
  58.             Console.ReadKey();
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement