Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace fizzbuzz_but_length_me
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = { }; //Numbers to test against, in order. Will be filled in by user later. NO TOUCHING
- string[] words = { }; //Words to add to output if testing against numbers is true. Will be filled in by user later. NO TOUCHING
- int length;
- string input;
- 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
- Regex regex = new Regex(pattern);
- while (true)
- {
- Console.Clear();
- for (int i = 0; i < numbers.Length; i++)
- {
- Console.WriteLine("Set " + (i+1).ToString() + ": " + numbers[i].ToString() + ", " + words[i]);
- }
- Console.WriteLine("What number do you want to match multiples of, and what word do you want to replace it with?");
- Console.WriteLine("Format your input as [number to match], [word to replace with]");
- input = Console.ReadLine();
- MatchCollection matches = regex.Matches(input);
- Match matchesGroups = regex.Match(input);
- if (matches.Count == 0) { Console.WriteLine("Invalid input. Try again."); Console.ReadKey(); }
- else
- {
- Group number = matchesGroups.Groups[1];
- Array.Resize(ref numbers, numbers.Length + 1);
- numbers[numbers.Length - 1] = Int32.Parse(number.ToString());
- Group word = matchesGroups.Groups[2];
- Array.Resize(ref words, words.Length + 1);
- words[words.Length - 1] = word.ToString();
- Console.WriteLine("Would you like to match against another number? y/n");
- if(Console.ReadKey().Key == ConsoleKey.N) { Console.Clear(); break; }
- }
- }
- Console.WriteLine("Numbers to output up to?");
- length = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- for (int i = 1; i <= length; i++)
- {
- string output = "";
- for (int j = 0; j < numbers.Length; j++)
- {
- if (i % (int)numbers.GetValue(j) == 0)
- {
- output = output + words.GetValue(j);
- }
- }
- if (output == "") { output = i.ToString(); }
- Console.WriteLine(output);
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement