본문 바로가기

Programming Language/C++

C++ 뒤집은 소수

-it취업을 위한 알고리즘 입문 (with c++): 창의적 문제해결 문제-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int prime[101];
int ints[101];
string s[101];
 
bool isPrime(int x){
 
    int chk;
    if (x >= 2){
        chk = 0;
        for (int i = 2; i < x; i++){
 
            if (x%i == 0){
                chk = 1;
                break;
            }
        }
    
        if (chk == 0){
            printf("%d ", x);
            return x;
        }
        
        else{
            return 0;
        }
    }
    
}
 
 
int reverse(int x){
 
    int tempi;
    string temp = to_string(x);
    reverse(temp.begin(), temp.end());
    tempi = stoi(temp);
    return isPrime(tempi);
}
 
int main(){
 
    int n;
    cin >> n;
    int temp;
 
    for (int i = 0; i < n; i++){
        cin >> s[i];
        temp = reverse(stoi(s[i]));
    }
 
    return 0;
}