Dahil di ako busy. Eto ituloy mo nalang.
Di ko sure kung ayan yung need mo pero according sa instructions, split yung given 20 lines into group by chunkSize
Note: remove mo nalang yung lines.Add(RandomString(length: 10)); kung tapos mo ng itest then manual input kana.
C#:
int numberOfLines = 20;
List<string> lines = new();
Console.WriteLine($"Enter the {numberOfLines} lines of poem");
for (int i = 1; i < numberOfLines + 1; i++) {
lines.Add(RandomString(length: 10));
// Console.Write($"L{i}: ");
// lines.Add(Console.ReadLine());
}
Console.Write("Enter number of lines for each stanza: ");
int chunkSize = Convert.ToInt32(Console.ReadLine());
var chunks = SplitByChunk(lines, chunkSize);
foreach (string[] chunk in chunks) {
foreach (var c in chunk)
Console.WriteLine(c);
Console.WriteLine();
}
static string[][] SplitByChunk(IEnumerable<string> source, int chunkSize) {
int i = 0;
return source.GroupBy(s => i++ / chunkSize).Select(g => g.ToArray()).ToArray();
}
static string RandomString(int length) {
var random = new Random();
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
Dahil random lang, eto magiging output niyan
Code:
79OLEG0KL1
DTOD0N6A0U
L6CAXZ2XCR
CJJ4IOB6XK
XV7MH6Y62K
I7WFQVV9XX
HVLRZD37TS
F4X6VRHDIQ
00V7YRTJV0
2LDDXDAAJ8
FJIQAZ5CQV
E2JAG06YQW
WZJY4W1C6F
XUH0GDDWJ5
SVY6L8PCNV
7VSPA964ZT
WM84M04C89
HCSCZZSESO
RF6IEQ84VM
8698EI176O
Note: Di ako expert, just wanted to help a little