Algorithm/BOJ

[BOJ] 10988 팰린드롬

yeeendy 2023. 1. 15. 20:17
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            //여기서 부터 작성하세요

            bool isTrue = true; 

            for(int i=0; i < str.Length - 1; i++)
            {
                if (str[i] == str.Length - 1 - i)
                {
                    isTrue = true; 
                }
                else
                {
                    isTrue = false;
                }
            }

            if (isTrue == true)
                Console.WriteLine("1");
            else
                Console.WriteLine("0");
        }
    }
}

이현아님 블로그 참고

bool형식을 활용하여

str[0] 자리의 알파벳과 str.Length-1 - i 의 문자를 참, 거짓 확인해보기

 

'Algorithm > BOJ' 카테고리의 다른 글

[BOJ] 5585 거스름돈  (0) 2023.01.17
[BOJ] 11659 구간 합 구하기 4  (0) 2023.01.16
[BOJ] 11720 숫자의 합  (0) 2023.01.15
[BOJ] 1120 문자열(미완)  (0) 2023.01.13
[BOJ] 10173 니모를 찾아서  (0) 2023.01.12