Matching Score csd Cognizant
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
// implement code here
var sizeOfFirstArr = Convert.ToInt32(Console.ReadLine());
var sizeOfSecondArr = Convert.ToInt32(Console.ReadLine());
var arrFirst = new int[sizeOfFirstArr];
var arrSecond = new int[sizeOfSecondArr];
var refer = new Program();
if (refer.ValidateArraySize(sizeOfFirstArr, sizeOfSecondArr) == "Valid Array size")
{
for (int i = 0; i < sizeOfFirstArr; i++)
{
var inp = Convert.ToInt32(Console.ReadLine());
if ("Valid element" == refer.ValidateElements(inp))
{
arrFirst[i] = inp;
}
else
{
throw new Exception("No negative element");
}
}
for (int i = 0; i < sizeOfSecondArr; i++)
{
var inp = Convert.ToInt32(Console.ReadLine());
if ("Valid element" == refer.ValidateElements(inp))
{
arrSecond[i] = inp;
}
else
{
throw new Exception("No negative element");
}
}
var match = refer.GetMatchingElements(arrFirst, arrSecond);
if (match.Length != 0)
{
foreach (var item in match)
{
Console.WriteLine(item);
}
}
else
{
Console.WriteLine("No Matching Score");
}
}
else
{
Console.WriteLine("Invalid array size");
}
}
// implement code here
public string ValidateArraySize(int input1, int input2)
{
if (input1 == input2)
return "Valid Array size";
else
return "Invalid array size";
}
public string ValidateElements(int input)
{
if (input > 0)
return "Valid element";
else
return "No Negative Element";
}
public string[] GetMatchingElements(int[] input1, int[] input2)
{
var match = new List<string>();
foreach (var item in input1)
{
if (Array.Exists(input2, element => element == item))
match.Add(Array.IndexOf(input1, item) + "," + Array.IndexOf(input2, item));
}
return match.ToArray();
}
}
}