코딩 테스트/BOJ

C# 10173 니모를 찾아서

s0002 2023. 1. 12. 22:29

먼저 니모가 가질 수 있는 문자열의 모든 경우를 nemo 배열에 넣었다

arr 배열의 문자열 안에 nemo배열의 값을 포함하고 있는지 찾게 했다

하나라도 포함하고 있으면 true가 반환되므로 for문 종료하고  결과를 출력하게 만들었다

포함하고 있지 않으면 for문 마지막까지 돌고 결과 출력한다

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Study11
{
    class App
    {
        //생성자 
        public App()
        {
            //[BOJ] 10173 니모를 찾아서 
            string[] arr = {
                "Marlin names this last egg Nemo, a name that Coral liked.",
                "While attempting to save nemo, Marlin meets Dory,",
                "a good-hearted and optimistic regal blue tang with short-term memory loss.",
                "Upon leaving the East Australian Current,(888*%$^&%0928375)Marlin and Dory",
                "NEMO leaves for school and Marlin watches NeMo swim away."
            };

            //여기서부터 작성 하세요 
            string[] nemo = { "nemo", "nemO", "neMo", "neMO", "nEmo", "nEnO", "nENo", "nENO",
                "Nemo", "Nemo", "NeMo", "NeMO", "NEmo", "NEmO", "NEMo", "NEMO" };

            bool result = false;
            for(int i = 0; i < arr.Length; i++)
            {
                for(int j = 0; j < nemo.Length; j++)
                {
                    result=arr[i].Contains(nemo[j]);
                    if (result)
                        break;
                }
                if (result)
                    Console.WriteLine("Found");
                else
                    Console.WriteLine("Missing");
            }
            
            //출력 
            //Found
            //Found
            //Missing
            //Missing
            //Found
        }
    }
}

 

https://www.acmicpc.net/problem/10173

 

10173번: 니모를 찾아서

여러 문장이 각 줄로 입력되며, 입력의 마지막에는 "EOI" 입력된다. 한 줄은 최대 80개의 글자로 이루어져 있다.

www.acmicpc.net

 

'코딩 테스트 > BOJ' 카테고리의 다른 글

C# 1120 문자열  (0) 2023.01.13
C# 1181 단어 정렬  (0) 2023.01.12
C# 4458 첫 글자를 대문자로  (0) 2023.01.12
C# 2711 오타맨 고창영  (0) 2023.01.12
C# 9086 문자열  (0) 2023.01.12