Guest User

r/BadCode Submission

a guest
Mar 26th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.77 KB | None | 0 0
  1. class CharCounter
  2.     {
  3.  
  4.         /*
  5.          * This includes unnecessary big Arrays and Array constructs.
  6.          * It is also not really threadsafe.
  7.          * It only can handle those chars on the keyboard. Nobody uses other stuff right? right?
  8.          * It uses advaced Threadingtechniques to prevent the PC from crashing.
  9.          * Im also using my own get chars method because i dont trust the system methods.
  10.          * I follow the Java coding guidelines although I use C#
  11.          */
  12.  
  13.         public static void printChars(string m) {
  14.             Tuple<char, int>[] l = count(m);
  15.             foreach (Tuple<char, int> n in l){
  16.                 Console.WriteLine(n.Item1 + " = " + n.Item2);
  17.             }
  18.         }
  19.  
  20.         public static Tuple<char, int>[] count(string o){
  21.             Console.WriteLine("Processing..-");
  22.             char[] a = getChars(o);
  23.             int b = a.Length;
  24.             int c = 0;
  25.             Tuple<char, int>[] d = new Tuple<char, int>[] {
  26.                 new Tuple<char, int>('a', 0),
  27.                 new Tuple<char, int>('b', 0),
  28.                 new Tuple<char, int>('c', 0),
  29.                 new Tuple<char, int>('d', 0),
  30.                 new Tuple<char, int>('e', 0),
  31.                 new Tuple<char, int>('f', 0),
  32.                 new Tuple<char, int>('g', 0),
  33.                 new Tuple<char, int>('h', 0),
  34.                 new Tuple<char, int>('i', 0),
  35.                 new Tuple<char, int>('j', 0),
  36.                 new Tuple<char, int>('k', 0),
  37.                 new Tuple<char, int>('l', 0),
  38.                 new Tuple<char, int>('m', 0),
  39.                 new Tuple<char, int>('n', 0),
  40.                 new Tuple<char, int>('o', 0),
  41.                 new Tuple<char, int>('p', 0),
  42.                 new Tuple<char, int>('q', 0),
  43.                 new Tuple<char, int>('r', 0),
  44.                 new Tuple<char, int>('s', 0),
  45.                 new Tuple<char, int>('t', 0),
  46.                 new Tuple<char, int>('u', 0),
  47.                 new Tuple<char, int>('v', 0),
  48.                 new Tuple<char, int>('w', 0),
  49.                 new Tuple<char, int>('x', 0),
  50.                 new Tuple<char, int>('y', 0),
  51.                 new Tuple<char, int>('z', 0),
  52.                 new Tuple<char, int>('A', 0),
  53.                 new Tuple<char, int>('B', 0),
  54.                 new Tuple<char, int>('C', 0),
  55.                 new Tuple<char, int>('D', 0),
  56.                 new Tuple<char, int>('E', 0),
  57.                 new Tuple<char, int>('F', 0),
  58.                 new Tuple<char, int>('G', 0),
  59.                 new Tuple<char, int>('H', 0),
  60.                 new Tuple<char, int>('I', 0),
  61.                 new Tuple<char, int>('J', 0),
  62.                 new Tuple<char, int>('K', 0),
  63.                 new Tuple<char, int>('L', 0),
  64.                 new Tuple<char, int>('M', 0),
  65.                 new Tuple<char, int>('N', 0),
  66.                 new Tuple<char, int>('O', 0),
  67.                 new Tuple<char, int>('P', 0),
  68.                 new Tuple<char, int>('Q', 0),
  69.                 new Tuple<char, int>('R', 0),
  70.                 new Tuple<char, int>('S', 0),
  71.                 new Tuple<char, int>('T', 0),
  72.                 new Tuple<char, int>('U', 0),
  73.                 new Tuple<char, int>('V', 0),
  74.                 new Tuple<char, int>('W', 0),
  75.                 new Tuple<char, int>('X', 0),
  76.                 new Tuple<char, int>('Y', 0),
  77.                 new Tuple<char, int>('Z', 0),
  78.                 new Tuple<char, int>('1', 0),
  79.                 new Tuple<char, int>('2', 0),
  80.                 new Tuple<char, int>('3', 0),
  81.                 new Tuple<char, int>('4', 0),
  82.                 new Tuple<char, int>('5', 0),
  83.                 new Tuple<char, int>('6', 0),
  84.                 new Tuple<char, int>('7', 0),
  85.                 new Tuple<char, int>('8', 0),
  86.                 new Tuple<char, int>('9', 0),
  87.                 new Tuple<char, int>('0', 0),
  88.                 new Tuple<char, int>('^', 0),
  89.                 new Tuple<char, int>('!', 0),
  90.                 new Tuple<char, int>('"', 0),
  91.                 new Tuple<char, int>('§', 0),
  92.                 new Tuple<char, int>('$', 0),
  93.                 new Tuple<char, int>('%', 0),
  94.                 new Tuple<char, int>('&', 0),
  95.                 new Tuple<char, int>('/', 0),
  96.                 new Tuple<char, int>('(', 0),
  97.                 new Tuple<char, int>(')', 0),
  98.                 new Tuple<char, int>('=', 0),
  99.                 new Tuple<char, int>('?', 0),
  100.                 new Tuple<char, int>('´', 0),
  101.                 new Tuple<char, int>('`', 0),
  102.                 new Tuple<char, int>('°', 0),
  103.                 new Tuple<char, int>('²', 0),
  104.                 new Tuple<char, int>('³', 0),
  105.                 new Tuple<char, int>('{', 0),
  106.                 new Tuple<char, int>('[', 0),
  107.                 new Tuple<char, int>(']', 0),
  108.                 new Tuple<char, int>('}', 0),
  109.                 new Tuple<char, int>('\\', 0),
  110.                 new Tuple<char, int>('+', 0),
  111.                 new Tuple<char, int>('+', 0),
  112.                 new Tuple<char, int>('~', 0),
  113.                 new Tuple<char, int>('#', 0),
  114.                 new Tuple<char, int>('\'', 0),
  115.                 new Tuple<char, int>('-', 0),
  116.                 new Tuple<char, int>('_', 0),
  117.                 new Tuple<char, int>('.', 0),
  118.                 new Tuple<char, int>(':', 0),
  119.                 new Tuple<char, int>(';', 0),
  120.                 new Tuple<char, int>(',', 0),
  121.                 new Tuple<char, int>('<', 0),
  122.                 new Tuple<char, int>('>', 0),
  123.                 new Tuple<char, int>('|', 0),
  124.                 new Tuple<char, int>('ö', 0),
  125.                 new Tuple<char, int>('ä', 0),
  126.                 new Tuple<char, int>('ü', 0),
  127.                 new Tuple<char, int>('Ö', 0),
  128.                 new Tuple<char, int>('Ä', 0),
  129.                 new Tuple<char, int>('Ü', 0)
  130.             };
  131.             while (c != b){
  132.                 bool p = false;
  133.                 foreach (Tuple<char, int> e in d){
  134.                     if(e.Item1 == a[c]){
  135.                         Tuple<char, int> f = new Tuple<char, int>(e.Item1, e.Item2 + 1);
  136.                         int g = Array.IndexOf(d, e);
  137.                         d[g] = f;
  138.                         p = true;
  139.                     }
  140.                     Console.Write(".");
  141.                     Thread.Sleep(10);
  142.                 }
  143.                 if(!p){
  144.                     throw new Exception("You typed a wrong char!");
  145.                 }
  146.                 c++;
  147.             }
  148.             Random h = new Random();
  149.             Tuple<char, int>[] i = d.OrderBy(x => h.Next()).ToArray();
  150.             return i;
  151.         }
  152.  
  153.         public static char[] getChars(string j){
  154.             char[] k = new char[j.Length];
  155.             for (int i = 0; i < j.Length; i++){
  156.                 k[i] = j[i];
  157.             }
  158.             return k;
  159.         }
  160.     }
Advertisement
Add Comment
Please, Sign In to add comment