반응형
#include <iostream>
using namespace std;
int reverse(int x)
{
int res = 0, tmp;
while (x > 0)
{
tmp = x % 10;
res = res * 10 + tmp;
x = x / 10;
}
return res;
}
bool isPrime(int x)
{
int i;
if (x == 1) return false;
for (i = 2; i <= x / 2; ++i)
{
if (x % i == 0) return false;
}
return true;
}
int main()
{
int n, i, num, temp;
cin >> n;
for (i = 0; i < n; ++i)
{
cin >> num;
temp = reverse(num);
if (isPrime(temp)) cout << temp << " ";
}
return 0;
}
출력 결과
채점 결과
해당 포스트는 'it 취업을 위한 알고리즘 문제풀이 (with C/C++) : 코딩테스트 대비' 강의를 수강하며 개인 백업용으로 메모하였습니다.
인프런: https://www.inflearn.com/course/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98#
반응형