Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
With Arguments
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 /* Correct Inputs : {} , {"--NAME", "codility#"} ,{"--COUNT", "100"},{"--HELP"} , {"--NAME", "code","--COUNT", "50"} , {"--NAME", "code$","--HELP"} , {"--COUNT", "10","--HELP"} , {"--COUNT", "50","--NAME", "code"} , {"--HELP","--NAME", "code$"} , {"--HELP","--COUNT", "10"} , , {"--NAME", "codility#","--COUNT", "10","--HELP"} , {"--COUNT","10","--NAME", "codility#", "--HELP"} {"--HELP", "--COUNT","10","--NAME", "codility#"} , {"--HELP","--NAME", "codility#","--COUNT", "10"} {"--NAME", "codility#","--HELP","--COUNT", "10"} , {"--COUNT","10","--HELP","--NAME", "codility#"} Wrong Inputs: Character checking : {"--NAME","XX"}, {"--NAME","xxx"} , {"--NAME","abcdex78nm"} , Count checking : {"--COUNT", "101"}, {"--COUNT", "9"} , {"--COUNT", "-9"} {"--COUNT", "ssssss"}, {"--COUNT", "ss"} {"--COUNT", ""} , {"--NAME",""}, {"--HELP", "--NAME",""} , {"--HELP", "--COUNT",""} {"--HELP", "--NAME","8292"} , {"--HELP", "--COUNT","khkh"} {"kjkjkk"} {"--NAME", "codility#","--HELP","--COUNT", "10","--COUNT", "0"} */ using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var val = new ValidateArguments(); try{ args = new string[] {"--NAME", "codility#"}; var result = val.Validate(args); Console.WriteLine(result); }catch( Exception e){ Console.WriteLine( "Exception Occured: {0}", e.Message); } } } } public class ValidateArguments { private const int WRONG_ARGS = -1; private const int OK_ARGS = 0; private const int HELP_ARGS = 1; private const string NAME_ARG = "--NAME"; private const string COUNT_ARG = "--COUNT"; private const string HELP_ARG = "--HELP"; public int Validate(string[] args) { var help_present = false; var args_valid = true; for (var i = 0; i < args.Length;) { var arg = args[i].ToUpperInvariant(); if (arg == NAME_ARG) { if (i + 1 >= args.Length) { args_valid = false; break; } // we do not care whats up next var val = args[i + 1]; if(val.Length <= 3 || val.Length>=10){ args_valid = false; break; } i += 2; } else if (arg == COUNT_ARG) { if (i + 1 >= args.Length) { args_valid = false; break; } var val = args[i + 1]; int count = -1; if (!int.TryParse(val, out count)) { args_valid = false; break; } if(count < 10 || count > 100){ args_valid = false; break; } i += 2; } else if (arg == HELP_ARG) { help_present = true; i += 1; } else { args_valid = false; break; } } if (args_valid) { if (help_present) { return HELP_ARGS; } return OK_ARGS; } return WRONG_ARGS; } }
run
|
edit
|
history
|
help
0
Delegates
Fiddling around
linear search
SunLocation
Public access specifier
Byte array to base 64 string
Обненник 24/7
Unicode Braille Patterns.
code 1
Abstract Class