C# Subarray Division [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 int birthday(List<int> s, int d, int m)
{
//더한 수 와 d 가 맞을 때의 카운트 변수
int count = 0;
for(int i=0; i<s.Count; i++)
{
int tmp = 0;
//i 번째부터 i+m번째 까지 반복
for(int j=i; j<i+m; j++)
{
if(j==s.Count) break;
tmp += s[j];
}
//더한 tmp 가 d와 같다면 카운트 더하기
if(d==tmp) count++;
}
return count;
}
}
class Solution
{
public static void Main(string[] args)
{
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int n = Convert.ToInt32(Console.ReadLine().Trim());
List<int> s = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(sTemp => Convert.ToInt32(sTemp)).ToList();
string[] firstMultipleInput = Console.ReadLine().TrimEnd().Split(' ');
int d = Convert.ToInt32(firstMultipleInput[0]);
int m = Convert.ToInt32(firstMultipleInput[1]);
int result = Result.birthday(s, d, m);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
댓글