Last active
March 19, 2017 16:58
-
-
Save mohemohe/191f58974e174fe66edd to your computer and use it in GitHub Desktop.
競プロ用べんりクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
public static class Benri | |
{ | |
public static class StdIn | |
{ | |
public static int[] ReadStdIn() | |
{ | |
string[] str = Console.ReadLine().Split(' '); | |
List<int> list = new List<int>(); | |
foreach (var s in str) | |
{ | |
try | |
{ | |
list.Add(int.Parse(s)); | |
} | |
catch | |
{ | |
return null; | |
} | |
} | |
return list.ToArray(); | |
} | |
public static string[] ReadStdInStr() | |
{ | |
string[] str = Console.ReadLine().Split(' '); | |
List<string> list = new List<string>(); | |
foreach (var s in str) | |
{ | |
try | |
{ | |
list.Add(s); | |
} | |
catch | |
{ | |
return null; | |
} | |
} | |
return list.ToArray(); | |
} | |
} | |
public static class Sort | |
{ | |
public static void RadixSort(ref int[] array) | |
{ | |
var bucket = new List<int>[256]; | |
for (int d = 0, logR = 0; d < 4; d++, logR += 8) | |
{ | |
for (int i = 0; i < array.Length; i++) | |
{ | |
int key = (array[i] >> logR) & 255; | |
if (bucket[key] == null) | |
{ | |
bucket[key] = new List<int>(); | |
} | |
bucket[key].Add(array[i]); | |
} | |
for (int j = 0, i = 0; j < bucket.Length; j++) | |
{ | |
if (bucket[j] != null) | |
{ | |
foreach (int val in bucket[j]) | |
{ | |
array[i++] = val; | |
} | |
} | |
} | |
for (int j = 0; j < bucket.Length; j++) | |
{ | |
bucket[j] = null; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment