Outdated/Algorithm Solution

[BOJ] 10174번 팰린드롬

해달 2020. 4. 27. 08:00

복기

-


코드

  • C++ 17


#include <iostream>

#include <string>

 

using namespace std;

 

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

 

    int n;

    cin >> n;

 

    cin.ignore();

    while (n--)

    {

        string line;

        getline(cin, line);

        

        int len = line.size();

        bool isPalindrome = true;

        for (size_t i = 0; i < len / 2; i++)

        {

            char left = tolower(line[i]);

            char right = tolower(line[len - 1 - i]);

            if (left != right)

            {

                isPalindrome = false;

                break;

            }

        }

        

        if (isPalindrome)

            cout << "Yes\n";

        else

            cout << "No\n";

    }

}


  • C# 6.0


using System;

 

namespace Csharp

{

    class Program

    {

        static void Main(string[] args)

        {

            int N = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < N; i++)

            {

                string line = Console.ReadLine().ToLower();

                bool isPalindrome = true;

                for (int j = 0; j < line.Length / 2; j++)

                {

                    if (line[j] != line[line.Length - 1 - j])

                    {

                        isPalindrome = false;

                        break;

                    }

                }

 

                if (isPalindrome)

                    Console.WriteLine("Yes");

                else

                    Console.WriteLine("No");

            }

        }

    }

}


  • Python 3


from sys import stdin

input = stdin.readline

 

def isPalindrome(string):

    size = len(string)

    for i in range(size // 2):

        if string[i] != string[-1 - i]:

            return False    

    return True

 

N = int(input())

for _ in range(N):

    line = input().rstrip().lower()

    if isPalindrome(line):

        print('Yes')

    else:

        print('No')


'Outdated > Algorithm Solution' 카테고리의 다른 글

[BOJ] 2661번 좋은 수열  (0) 2020.05.04
[BOJ] 6581번 HTML  (0) 2020.04.27
[BOJ] 1083번 소트  (0) 2020.04.20
[BOJ] 1431번 시리얼 번호  (0) 2020.04.20
[BOJ] 3101번 토끼의 이동  (0) 2020.04.13