Skip to content

Instantly share code, notes, and snippets.

@rainbow23
Last active May 12, 2017 18:20
Show Gist options
  • Save rainbow23/b6bb39d998ef4bd434f41b4c2519857d to your computer and use it in GitHub Desktop.
Save rainbow23/b6bb39d998ef4bd434f41b4c2519857d to your computer and use it in GitHub Desktop.
paiza mondai
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IppAddrCheck
{
class Program
{
static void Main(string[] args)
{
string line = Console.ReadLine().Trim();
int ipAddrNum = Int32.Parse(line);
//Console.WriteLine("ipAddrNum: {0}", ipAddrNum);
string[] ipAddrs = new string[ipAddrNum];
for(int i = 0; i < ipAddrNum; i++)
{
string ipAddr = Console.ReadLine().Trim();
ipAddrs[i] = ipAddr;
//Console.WriteLine("ipAddrs[{0}] {1}", i, ipAddrs[i]);
}
List<List<string>> eachSegIpAddr = new List<List<string>>();
for (int i = 0; i < ipAddrNum; i++)
{
List<string> segIpNum = new List<string>();
segIpNum.AddRange(ipAddrs[i].Split('.'));
eachSegIpAddr.Add(segIpNum);
}
bool[] IsCorrectIpAddr = new bool[ipAddrNum];
int cnt = 0;
foreach (var segipAddr in eachSegIpAddr)
{
Console.WriteLine();
segipAddr.ForEach(i => Console.Write("{0} ", i));
Console.WriteLine();
int segIpJudge = 0;
foreach(var segIpN in segipAddr)
{
int aa;
bool result = Int32.TryParse(segIpN, out aa);
if (result)
{
int c = Int32.Parse(segIpN);
if (c > 0 && c < 100)
{
Console.WriteLine("setIp: {0} {1}", c, "true");
segIpJudge++;
}
else
{
Console.WriteLine("setIp: {0} {1}", c, "false");
segIpJudge--;
}
}
else
{
Console.WriteLine("ipの形式が間違い");
segIpJudge--;
}
}
if (segIpJudge == 4)
{
IsCorrectIpAddr[cnt] = true;
}
else
{
IsCorrectIpAddr[cnt] = false;
}
cnt++;
}
//kekka
for(int i =0; i< ipAddrNum; i++)
{
Console.WriteLine("{0} {1}", ipAddrs[i], IsCorrectIpAddr[i]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment