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

 

12904번: A와 B

수빈이는 A와 B로만 이루어진 영어 단어가 존재한다는 사실에 놀랐다. 대표적인 예로 AB (Abdominal의 약자), BAA (양의 울음 소리), AA (용암의 종류), ABBA (스웨덴 팝 그룹)이 있다. 이런 사실에 놀란 수

www.acmicpc.net

 

완성된 문자 T를 주어진 조건을 역순으로 하여 풀었다.

1. T의 끝 문자가 A일 시 A를 제거

2. T의 끝 문자가 B일 시  B를 제거 후, 뒤집기.

using System;
using System.Collections.Generic;
using System.Text;

namespace Baekjoon.Gold
{
    class _12904
    {
        static void Main(String[] args)
        {
            string s = Console.ReadLine();
            string str = Console.ReadLine();
            int n = str.Length - s.Length;

            for(int i = 0; i< n; i++)
            {
                if (str[str.Length - 1] == 'A')
                    str = str.Substring(0, str.Length - 1);
                else if (str[str.Length-1] == 'B')
                {
                    char[] c = str.Substring(0, str.Length - 1).ToCharArray();
                    Array.Reverse(c);
                    str = String.Join("", c);
                }
            }

            if (str == s)
                Console.WriteLine(1);
            else
                Console.WriteLine(0);
        }
    }
}

 

'문제 풀이 > C#' 카테고리의 다른 글

[24445] - 알고리즘 수업 - 너비 우선 탐색 2  (1) 2022.09.24
[24444] - 알고리즘 수업 - 너비 우선 탐색 1  (0) 2022.09.23
[23247] - Ten  (0) 2022.09.22
[2470] - 두 용액  (1) 2022.09.21
[2156] - 포도주 시식  (1) 2022.09.20

+ Recent posts