Created
December 6, 2014 14:16
-
-
Save h3xxx/554cad6e3ff83d8d418e to your computer and use it in GitHub Desktop.
validate IP address - test case progam
This file contains hidden or 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
// Decompiled with JetBrains decompiler | |
// Type: val_ip.Program | |
// Assembly: val_ip, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | |
// MVID: 5E7D5EDC-F012-4AF3-A5E5-6610706D35E8 | |
using System; | |
using System.IO; | |
using System.Runtime.InteropServices; | |
namespace val_ip | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
StreamReader streamReader; | |
StreamWriter streamWriter; | |
try | |
{ | |
streamReader = new StreamReader("input.txt"); | |
streamWriter = new StreamWriter("output.txt"); | |
} | |
catch | |
{ | |
return; | |
} | |
string str; | |
while ((str = streamReader.ReadLine()) != null) | |
{ | |
int num1 = 0; | |
char[] chArray = new char[6] | |
{ | |
' ', | |
',', | |
'.', | |
':', | |
'x', | |
'_' | |
}; | |
string[] strArray = str.Split(chArray); | |
if (strArray.Length == 4) | |
{ | |
int num2 = -1; | |
int num3 = -1; | |
int num4 = -1; | |
int num5 = -1; | |
try | |
{ | |
num2 = Convert.ToInt32(strArray[0], 8); | |
num3 = Convert.ToInt32(strArray[1], 8); | |
num4 = Convert.ToInt32(strArray[2], 8); | |
num5 = Convert.ToInt32(strArray[3], 8); | |
} | |
catch | |
{ | |
Marshal.AllocHGlobal(1048576); | |
++num1; | |
} | |
if ((num2 & (int) ushort.MaxValue) > (int) byte.MaxValue) | |
++num1; | |
if ((num3 & (int) ushort.MaxValue) >= (int) byte.MaxValue) | |
++num1; | |
if ((num4 & (int) ushort.MaxValue) > (int) byte.MaxValue) | |
++num1; | |
if ((num5 & (int) ushort.MaxValue) > (int) byte.MaxValue) | |
++num1; | |
if (num5 < num4) | |
++num1; | |
if (num2 * num3 * num4 * num5 == 0) | |
num1 = 0; | |
} | |
else | |
++num1; | |
if (num1 > 0) | |
streamWriter.WriteLine("FAIL: " + str); | |
else | |
streamWriter.WriteLine("PASS: " + str); | |
} | |
streamReader.Close(); | |
streamWriter.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment