Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Nth/C-sharp/nth-1.cs
Normal file
32
Task/Nth/C-sharp/nth-1.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
private static string Ordinalize(int i)
|
||||
{
|
||||
i = Math.Abs(i);
|
||||
|
||||
if (new[] {11, 12, 13}.Contains(i%100))
|
||||
return i + "th";
|
||||
|
||||
switch (i%10)
|
||||
{
|
||||
case 1:
|
||||
return i + "st";
|
||||
case 2:
|
||||
return i + "nd";
|
||||
case 3:
|
||||
return i + "rd";
|
||||
default:
|
||||
return i + "th";
|
||||
}
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
Console.WriteLine(string.Join(" ", Enumerable.Range(0, 26).Select(Ordinalize)));
|
||||
Console.WriteLine(string.Join(" ", Enumerable.Range(250, 16).Select(Ordinalize)));
|
||||
Console.WriteLine(string.Join(" ", Enumerable.Range(1000, 26).Select(Ordinalize)));
|
||||
}
|
||||
}
|
||||
22
Task/Nth/C-sharp/nth-2.cs
Normal file
22
Task/Nth/C-sharp/nth-2.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
|
||||
static string Ordinalize(int i)
|
||||
{
|
||||
return i + (
|
||||
i % 100 is >= 11 and <= 13 ? "th" :
|
||||
i % 10 == 1 ? "st" :
|
||||
i % 10 == 2 ? "nd" :
|
||||
i % 10 == 3 ? "rd" :
|
||||
"th");
|
||||
}
|
||||
|
||||
static void PrintRange(int begin, int end)
|
||||
{
|
||||
for(var i = begin; i <= end; i++)
|
||||
Console.Write(Ordinalize(i) + (i == end ? "" : " "));
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
PrintRange(0, 25);
|
||||
PrintRange(250, 265);
|
||||
PrintRange(1000, 1025);
|
||||
Loading…
Add table
Add a link
Reference in a new issue