문제 풀이/C#
[12904] - A와 B
Chamber
2022. 9. 19. 19:01
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);
}
}
}