[백준/C#] 10807번 개수 세기

dev.hyeon·2022년 7월 5일
0

알고리즘

목록 보기
11/44
post-thumbnail

10807번 개수 세기

풀이

총 N개의 정수가 주어졌을 때, 정수 v가 몇 개인지 구하는 문제이다.
문자열로 받은 N개의 수를 int.Parse() 함수를 이용해 정수로 변환하여 v와 비교한다. 두 값이 같다면 count를 증가시키고 모든 정수에 대해 비교한 후 결과값인 count를 출력한다.

코드

using System;
namespace BJ_10871{
    class Program{
        static void Main(string[] arg){
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split();
            int v = int.Parse(Console.ReadLine());
            int count = 0;
            
            for (int i = 0; i < n; i++){
                if (v == int.Parse(s[i]))
                    count++;
            }
            Console.WriteLine(count);
        }
    }
}

0개의 댓글