SWEA

[SWEA] 초심자의 회문 검사

itsnot4me 2024. 9. 25. 20:50

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PyTLqAf4DFAUq&categoryId=AV5PyTLqAf4DFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

import java.util.Scanner;
import java.io.FileInputStream;

class Solution
{
	public static void main(String args[]) throws Exception
	{
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();

		for(int test_case = 1; test_case <= T; test_case++)
		{
			String word = sc.next();
            String reverse = "";
            for(int i=0; i<word.length(); i++){
                reverse = reverse + word.charAt(word.length()-i-1);
            }
            if(word.equals(reverse))
            System.out.println("#"+test_case+" "+1);
            else
            System.out.println("#"+test_case+" "+0);
		}
	}
}

 

reverse에 단어 거꾸로 집어넣고 (char로 변환해서 끝부터)

reverse랑 word 문자열 같은지 확인 후 같으면 1 (회문O) 아니면 0 (회문X)

'SWEA' 카테고리의 다른 글

[SWEA] 중간 평균값 구하기  (2) 2024.09.26
[SWEA] 지그재그 숫자  (1) 2024.09.26
[SWEA] 파리 퇴치  (0) 2024.09.25
[SWEA] 파스칼의 삼각형  (1) 2024.09.24
[SWEA] 패턴 마디의 길이  (0) 2024.09.21