YWC
백준/1259/팰린드롬수/C/Python 본문
https://www.acmicpc.net/problem/1259
1259번: 팰린드롬수
입력은 여러 개의 테스트 케이스로 이루어져 있으며, 각 줄마다 1 이상 99999 이하의 정수가 주어진다. 입력의 마지막 줄에는 0이 주어지며, 이 줄은 문제에 포함되지 않는다.
www.acmicpc.net
1) c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable:4996)
int main(void) {
while (1) {
char arr[99999] = { 0, };
int check = 1;
scanf("%s", arr);
if (arr[0] == '0') { return 0; }
int lenn = strlen(arr);
for (int i = 0; i < lenn/2; i++) {
// printf(">>%c %c\n", arr[i], arr[lenn-1-i]);
if (arr[i] != arr[lenn - 1 - i]) { check = 0; break; }
}
if (check == 1) { printf("yes\n"); }
else { printf("no\n"); }
}
return 0;
}
2) Python
def make_list(number):
num_list=[]
while(True):
num_list.append(number%10)
if number//10 < 1:
break
number = number//10
return(num_list)
def fun1(number):
num_list = make_list(number)
size_list = len(num_list)
for idx in range(0, len(num_list)//2):
#print(f"{idx},{size_list-idx-1}")
if num_list[idx] != num_list[size_list-idx-1]:
print("no")
return
print("yes")
if __name__=="__main__":
while(True):
n = int(input())
if n==0:
break
fun1(n)
'공부 > 코테_문제풀이' 카테고리의 다른 글
백준/2609/최대공약수최소공배수/C/Python (0) | 2023.09.11 |
---|---|
백준/1546/평균/C/Python (0) | 2023.09.11 |
백준/2798/블랙잭/C/Python (0) | 2023.09.11 |
백준/2292/벌집/C/Python (0) | 2023.09.11 |
백준/2231/분해합/C/Python (0) | 2023.09.06 |