Перевод кода с Pascal на C# - C# (183515)
Формулировка задачи:
var
k,n: integer;
d: char;
procedure AddDigit(s: string);
var
c,i: char;
begin
if Length(s)=k then writeln(s)
else begin
if s='' then c:='1' else c:= Succ(s[Length(s)]);
for i:=c to d do AddDigit(s+i)
end
end;
begin
k:= 2;
n:= 5;
d:= Chr(48+n);
AddDigit('');
readln
end.Решение задачи: «Перевод кода с Pascal на C#»
textual
Листинг программы
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
public static void Main()
{
int k = 2;
int n = 5;
Queue<List<int>> q = new Queue<List<int>>();
q.Enqueue(new List<int>(k));
while (q.Count != 0)
{
List<int> prev = q.Dequeue();
if (prev.Count == k)
{
Console.WriteLine(String.Join(String.Empty, prev.Select(i => i.ToString())));
}
else
{
for (int i = prev.LastOrDefault() + 1; i <= n; i++)
{
List<int> next = new List<int>(prev);
next.Add(i);
q.Enqueue(next);
}
}
}
}
}