[백준/JAVA]10988번 팰린드롬인지 확인하기

2025. 1. 21. 13:19·코딩테스트/백준

문제

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

주어진 문자열이 팰린드롬(앞뒤가 같은 문자열)인지 검사하는 문제였다.

문제 풀이

1. toCharArray()

import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        char[] words=br.readLine().toCharArray();
        int result=1;
        
        for(int i=0;i<words.length/2;i++){
            if(words[i]!=words[words.length-i-1]){
                result=0;
                break;
            }
        }
        
        System.out.print(result);
    }
}

2. split()

import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] words=br.readLine().split("");
        int result=1; 

        for(int i=0;i<words.length/2;i++){
            if(!words[i].equals(words[words.length-i -1])){
                result=0; 
                break;
            }
        }

        System.out.print(result);
    }
}

'코딩테스트 > 백준' 카테고리의 다른 글

[백준/JAVA]2941번 크로아티아 알파벳  (0) 2025.01.22
[백준/JAVA]1157번 단어 공부  (0) 2025.01.21
[백준/JAVA]2444번 별 찍기 - 7  (0) 2025.01.21
[백준/JAVA]3003번 킹, 퀸, 룩, 비숍, 나이트, 폰  (1) 2025.01.20
[백준/JAVA]25083번 새싹🌱  (0) 2025.01.20
'코딩테스트/백준' 카테고리의 다른 글
  • [백준/JAVA]2941번 크로아티아 알파벳
  • [백준/JAVA]1157번 단어 공부
  • [백준/JAVA]2444번 별 찍기 - 7
  • [백준/JAVA]3003번 킹, 퀸, 룩, 비숍, 나이트, 폰
yxxjxxeee
yxxjxxeee
  • yxxjxxeee
    공부 일지
    yxxjxxeee
  • 전체
    오늘
    어제
    • study N
      • Framework
        • Spring
      • Language
        • JavaScript
        • C | C++
        • JAVA
        • PHP
      • CS
        • 네트워크
        • 자료구조
        • 데이터베이스
        • 운영체제
      • DBMS
        • MySQL
      • 코딩테스트 N
        • 백준 N
        • 프로그래머스
        • LeetCode
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 쇼핑몰 제작 프로젝트(PHP)
    • github
  • 공지사항

  • 인기 글

  • 최근 글

  • hELLO Designed By 정상우
    Version v4.10.2
yxxjxxeee
[백준/JAVA]10988번 팰린드롬인지 확인하기
상단으로

티스토리툴바