BaekJoon[C#]

문자열 단계 2941

wny0320 2022. 10. 3. 22:08

백준 온라인 코딩 문제풀이

https://www.acmicpc.net/

 

Baekjoon Online Judge

Baekjoon Online Judge 프로그래밍 문제를 풀고 온라인으로 채점받을 수 있는 곳입니다.

www.acmicpc.net

 

코드 참고

https://replit.com/@wny0320

 

wny0320 (박 상운)

Run code live in your browser. Write and run code in 50+ languages online with Replit, a powerful IDE, compiler, & interpreter.

replit.com

 

2941에 대해서 다룸

 


2941

using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        string[] str = {"c=","c-","dz=","d-","lj","nj","s=","z="};
        string Input = Console.ReadLine();
        for(int i = 0; i < str.Count(); i++)
        {
            if (Input.Contains(str[i]))
            {
                Input = Input.Replace(str[i], "a");
            }
        }
        Console.WriteLine(Input.Length);
    }
}

방법은 생각했지만 어떤 메소드를 써야할지 고민했던 문제

 

다른 풀이는 시작하는 알파벳 기준으로 하는 코드도 있었지만 비효율적이라고 생각

 

문제에서 주어진 크로아티아 알파벳을 str에 추가

 

Input을 받고 str에 있는 문자가 Input에 있을 시 그 문자를 a로 replace

 

길이를 출력

 

답을 보면 간단하지만 어떤 메소드를 사용할지와 문제 해결 방식을 생각하는 것이 어려웠던거 같음

'BaekJoon[C#]' 카테고리의 다른 글

기본 수학 1단계 1712  (0) 2022.10.05
문자열 단계 1316  (0) 2022.10.04
문자열 단계 5622  (0) 2022.09.28
문자열 단계 1152  (0) 2022.09.27
문자열 단계 2675  (0) 2022.09.26