Advertisement
Guest User

fuck me

a guest
Sep 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace fizzbuzz_but_length_me
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int[] numbers = { }; //Numbers to test against, in order. Will be filled in by user later. NO TOUCHING
  15.             string[] words = { }; //Words to add to output if testing against numbers is true. Will be filled in by user later. NO TOUCHING
  16.             int length;
  17.             string input;
  18.             string pattern = @"\b(?<number>\w+)[,]\s?(?<word>\w+)\b"; //This regex is used to grab the words and humbers from the user's input and put them in the arrays. ABSOLUTELY NO TOUCHING
  19.             Regex regex = new Regex(pattern);
  20.  
  21.             while (true)
  22.             {
  23.                 Console.Clear();
  24.                 for (int i = 0; i < numbers.Length; i++)
  25.                 {
  26.                     Console.WriteLine("Set " + (i+1).ToString() + ": " + numbers[i].ToString() + ", " + words[i]);
  27.                 }
  28.                 Console.WriteLine("What number do you want to match multiples of, and what word do you want to replace it with?");
  29.                 Console.WriteLine("Format your input as [number to match], [word to replace with]");
  30.                 input = Console.ReadLine();
  31.                 MatchCollection matches = regex.Matches(input);
  32.                 Match matchesGroups = regex.Match(input);
  33.                 if (matches.Count == 0) { Console.WriteLine("Invalid input. Try again."); Console.ReadKey(); }
  34.                 else
  35.                 {
  36.                     Group number = matchesGroups.Groups[1];
  37.                     Array.Resize(ref numbers, numbers.Length + 1);
  38.                     numbers[numbers.Length - 1] = Int32.Parse(number.ToString());
  39.                     Group word = matchesGroups.Groups[2];
  40.                     Array.Resize(ref words, words.Length + 1);
  41.                     words[words.Length - 1] = word.ToString();
  42.  
  43.                     Console.WriteLine("Would you like to match against another number? y/n");
  44.                     if(Console.ReadKey().Key == ConsoleKey.N) { Console.Clear(); break; }
  45.                 }
  46.                
  47.             }
  48.  
  49.             Console.WriteLine("Numbers to output up to?");
  50.             length = Convert.ToInt32(Console.ReadLine());
  51.             Console.Clear();
  52.  
  53.             for (int i = 1; i <= length; i++)
  54.             {
  55.                 string output = "";
  56.  
  57.                 for (int j = 0; j < numbers.Length; j++)
  58.                 {
  59.                     if (i % (int)numbers.GetValue(j) == 0)
  60.                     {
  61.                         output = output + words.GetValue(j);
  62.                     }
  63.                 }
  64.                 if (output == "") { output = i.ToString(); }
  65.  
  66.                 Console.WriteLine(output);
  67.             }
  68.             Console.ReadKey();
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement