본문 바로가기
알고리즘/백준 BOJ

[ BOJ/C# ] 2941 크로아티아 알파벳

by 왹져박사 2023. 11. 6.
728x90

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

 

2941번: 크로아티아 알파벳

예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z=

www.acmicpc.net

using System;
using System.IO;

namespace B2941
{
    class Program
    {
        static void Main()
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            string input = sr.ReadLine();
            int count = 0;
            for (int i = 0; i < input.Length; i++) 
            {
                if((i + 1) < input.Length)
                {
                    if (input[i] == 'c')
                    {
                        if (input[i + 1] == '=' || input[i + 1] == '-') i++;
                        count++;
                    }
                    else if (input[i] == 'd')
                    {
                        if (((i + 2) < input.Length && input[i + 1] == 'z' && input[i + 2] == '=')) i += 2;
                        else if (input[i + 1] == '-') i++;
                        count++;
                    }
                    else if (i < input.Length - 1 && input[i + 1] == 'j')
                    {
                        if (input[i] == 'l' || input[i] == 'n') i++;
                        count++;
                    }
                    else if (i < input.Length - 1 && (input[i + 1] == '='))
                    {
                        if (input[i] == 's' || input[i] == 'z') i++;
                        count++;
                    }
                    else count++;
                }
                else count++;
            }
            sw.Write(count);
            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

728x90

'알고리즘 > 백준 BOJ' 카테고리의 다른 글

[ BOJ/C# ] 1065 한수  (0) 2023.11.08
[ BOJ/C# ] 4673 셀프 넘버  (0) 2023.11.07
[ BOJ/C# ] 1789 수들의 합  (0) 2023.11.06
[ BOJ/C# ] 16435 스네이크버드, 골드  (0) 2023.11.05
[ BOJ/C# ] 1427 소트인사이드  (0) 2023.11.04