알고리즘/백준 BOJ

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

왹져박사 2023. 11. 6. 23:55

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();
        }
    }
}