Advertisement
Guest User

Untitled

a guest
Nov 21st, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. class GeneratingCombinations
  3. {
  4.     static void Main()
  5.     {
  6.         int n = int.Parse(Console.ReadLine());
  7.         int k = int.Parse(Console.ReadLine());
  8.  
  9.         for (int i = 0; i < Math.Pow(n, k); i++)
  10.         {
  11.             int conv = i;
  12.             int[] num = new int[k];
  13.             for (int j = 0; j < k; j++)
  14.             {
  15.                 num[j] = conv % n;
  16.                 conv = conv / n;
  17.             }
  18.  
  19.             bool areIncreasing = true;
  20.  
  21.             for (int m = 0; m < k - 1; m++)
  22.             {
  23.                 if (num[m] > num[m + 1] || num[m] == num[m + 1])
  24.                 {
  25.                     areIncreasing = false;
  26.                 }
  27.             }
  28.  
  29.             if (areIncreasing)
  30.             {
  31.                 Console.Write("{0}{1}", '{', num[0] + 1);
  32.                 for (int j = 1; j < k; j++)
  33.                 {
  34.                     Console.Write(", {0}", num[j] + 1);
  35.                 }
  36.                 Console.WriteLine("}");
  37.             }
  38.         }            
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement