백준_1259번_팰린드롬수

임정민·2023년 2월 23일
2

알고리즘 문제풀이

목록 보기
36/173
post-thumbnail

코딩테스트 연습 스터디 진행중 입니다. ✍✍✍
Notion : https://www.notion.so/1c911ca6572e4513bd8ed091aa508d67

문제

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

[나의 풀이]


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        String input;

        while(true){
            
            input = br.readLine();
            if(input.equals("0")){
                break;
            }

            for(int i = 0;i<=input.length()/2;i++){
                if(input.charAt(i)!=input.charAt(input.length()-i-1)){
                    bw.write("no\n");
                    break;
                }
                if(i==input.length()/2){
                    bw.write("yes\n");
                }
                
            }

        }

        bw.flush();
        bw.close();

    }
    
}

[팀원의 풀이]

# coding = utf-8

import sys
input = sys.stdin.readline

while True :
    s = input().rstrip()
    if s == str(0) :
        break
    l, r = 0, len(s)-1
    flag = True
    while l <= r:
        if s[l] == s[r]:
            l += 1
            r -= 1
        else:
            print("no")
            flag = False
            break
    if flag:
        print("yes")

간단한 문제입니다. String 객체를 String.charAt() 메서드를 활용하여 index별로 접근하여 풀었습니다.🙉🙉🙉

감사합니다.🍳🍳🍳

profile
https://github.com/min731

1개의 댓글

comment-user-thumbnail
2023년 2월 28일

답글 달기