본문 바로가기
개발공간

C# Compare the Triplets [HackerRank]

by -0o0- 2021. 8. 31.

C# Compare the Triplets [HackerRank]

 

using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Result
{
    public static List<int> compareTriplets(List<int> a, List<int> b)
    {
        int aNum=0, bNum=0;
        
        //각 리스트 i 번째를 비교하고 큰것에 1을 더함
        for(int i=0; i<a.Count; i++)
        {
            if(a[i]>b[i]) aNum++;
            else if(a[i]<b[i]) bNum++;
            else continue;
        }
        
        //반환을 위해 리스트 선언 후 a, b를 차례대로 Add
        List<int> result = new List<int>();
        result.Add(aNum);
        result.Add(bNum);
        
        return result;
    }

}

class Solution
{
    public static void Main(string[] args)
    {
        TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);

        List<int> a = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(aTemp => Convert.ToInt32(aTemp)).ToList();

        List<int> b = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(bTemp => Convert.ToInt32(bTemp)).ToList();

        List<int> result = Result.compareTriplets(a, b);

        textWriter.WriteLine(String.Join(" ", result));

        textWriter.Flush();
        textWriter.Close();
    }
}

댓글