Algorithm/프로그래머스

C#) [프로그래머스] 옹알이 (1)

HSH12345 2023. 1. 19. 21:49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _230119_3
{
    class Program
    {
        static void Main()
        {
            string[] babbling = { "ayaye", "uuuma", "ye", "yemawoo", "ayaa" };
            var result = new Solution().solution(babbling);
            Console.WriteLine(result);
        }
    }

    public class Solution
    {
        public int solution(string[] babbling)
        {            
            int answer = 0;

            //여기서부터 작성하세요  
            for (int i = 0; i < babbling.Length; i++)
            {
                string temp = "";
                
                temp = babbling[i].Replace("aya", " ").Replace("ye", " ").Replace("woo", " ").Replace("ma", " ").Replace(" ", "");  //우선 가능한 옹알이를 바로 널값으로 
                Console.WriteLine(temp);                                                //대체하는 것이아닌 공백으로 처리하고 마지막에 공백을 널로 대체해야 함(ex.wyeoo)
                if (String.IsNullOrEmpty(temp))
                {
                    answer++;
                }
            }
            return answer;
        }
    }
}