palindrom

I have been testing a few number to find error

help me debugging...


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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337

#include <iostream>
#include <string>
#include <vector>
using namespace std;



bool palindrom(int num){
    
  	int rem,sum=0,numCopy;	//Defining variables.
    numCopy=num;
    
	while(num!=0)	//Loop to reverse the number.
	{
		rem=num%10;
		num=num/10;
		sum=sum*10+rem;
        
	}
    
    if(numCopy==sum) return true;
	else return false;
}

int binary(int number) {
    int remainder;
    
    if(number <= 1) {
        return number;
    }
    
    
    remainder = number%2;
    binary(number >> 1);
    return remainder;
}

void base2(int num,vector<int>& str){
   
        
    if( num <=0) return;
   
    base2(num/2,str);
    //cout << "pushing back.."<< num%2 << endl;
    str.push_back(num%2);
    //cout << num%2;
    
    
}
void base3(int num,vector<int>& str){
    
    
    if( num <=0) return;
    
    base3(num/3,str);
    //cout << "pushing back" << endl;
    str.push_back(num%3);
    //cout <<"->"<< num%3;
    
    
}
void base4(int num,vector<int>& str){
    if( num <=0) return;
    base4(num/4,str);
    str.push_back(num%4);}
void base5(int num,vector<int>& str){
    if( num <=0) return;
    base5(num/5,str);
    str.push_back(num%5);}
void base6(int num,vector<int>& str){
    if( num <=0) return;
    base6(num/6,str);
    str.push_back(num%6);}
void base7(int num,vector<int>& str){
    if( num <=0) return;
    base7(num/7,str);
    str.push_back(num%7);}
void base8(int num,vector<int>& str){
    if( num <=0) return;
    base8(num/8,str);
    str.push_back(num%8);
    //cout << num%8;
}
void base9(int num,vector<int>& str){
    if( num <=0) return;
    base9(num/9,str);
    str.push_back(num%9);}
void base11(int num,vector<int>& str){
    if( num <=0) return;
    base11(num/11,str);
    str.push_back(num%11);}
void base12(int num,vector<int>& str){
    if( num <=0) return;
    base12(num/12,str);
    str.push_back(num%12);}
void base13(int num,vector<int>& str){
    if( num <=0) return;
    base13(num/13,str);
    str.push_back(num%13);}
void base14(int num,vector<int>& str){
    if( num <=0) return;
    base14(num/14,str);
    str.push_back(num%14);}
void base15(int num,vector<int>& str){
    if( num <=0) return;
    base12(num/15,str);
    str.push_back(num%15);}
void base16(int num,vector<int>& str){
    if( num <=0) return;
    base12(num/16,str);
    str.push_back(num%16);}




bool palindrome_2(vector<int>&vec,int begin,int end){
    
    if(begin >= end) {
        //cout << "returning true..."<<endl;
        return true;
       
    }
     
    
    if( vec[begin] != vec[end]  ) {
        //cout << vec[begin] << " and " << vec[end] <<endl;
        //cout << " returning false..."<<endl;
        return false;
            }

     return palindrome_2(vec,begin+1,end-1);
    
        
    
}


void clear(vector<int>& vec){
    
    while( vec.size() !=0){
        
        vec.pop_back();
    }
}

void print(vector<int>& vec){
    
    for(int i=0 ; i < vec.size(); i++){
        cout << vec[i] <<endl;
        
    }
    
}
int main (int argc, const char * argv[])
{
    int palin;
    vector<int> str;
    bool result;
    vector<int> resultVec;
    
    while(true){
        cin >> palin;
        //if(palin ==0) return 0;
        if( palin <= 0 || palin >= 50000) return 0;
        
        //cout << "result...." <<endl;
        result = false;
        
        
        clear(str);
        base2(palin,str);
        
        //print(str);
        
        if(palindrome_2(str,0,(str.size()-1))==true) {
            
            result = true;
        
        }
            clear(str);
            base3(palin, str);
        if(palindrome_2(str,0,str.size()-1) ==true){ 
            result = true;}
            
            clear(str);
            base4(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true){ 
            result = true;}
            
            clear(str);
            base5(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;}
            
            clear(str);
            base6(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;}
            
            clear(str);
            base7(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;}
            
            clear(str);
            base8(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;}
            
            clear(str);
            base9(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;}
            
            clear(str);
        if( palindrom(palin)==true ) {
            result = true;}
            
            base11(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;}
            
            clear(str);
            base12(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true){ 
            result = true;}
            
            clear(str);
            base13(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;}
            
            clear(str);
            base14(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true){ 
            result = true;}
            
            clear(str);
            base15(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;}
            
            clear(str);
            base16(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {
            result = true;
        }
        
        //cout << "result : " << result <<endl;
        if( result == true){
        
     //========================================================
        
       
        cout << "Number " << palin <<" is palindrom basis";
        clear(str);
        base2(palin,str);
        if(palindrome_2(str,0,(str.size()-1))==true) {cout <<" 2";
            result = true;}
        clear(str);
            base3(palin, str);
        if(palindrome_2(str,0,str.size()-1) ==true){ cout <<" 3"; 
            result = true;}

        clear(str);
            base4(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true){ cout <<" 4";
            result = true;}

        clear(str);
            base5(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 5";
            result = true;}

        clear(str);
            base6(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 6";
            result = true;}

        clear(str);
            base7(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 7";
            result = true;}

        clear(str);
            base8(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 8";
            result = true;}

        clear(str);
            base9(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 9";
            result = true;}

            clear(str);
        if( palindrom(palin)==true ) {cout << " 10";
            result = true;}

            base11(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 11";
            result = true;}

        clear(str);
            base12(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true){ cout <<" 12";
            result = true;}

        clear(str);
            base13(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 13";
            result = true;}

        clear(str);
            base14(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true){ cout <<" 14";
            result = true;}

        clear(str);
            base15(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 15";
            result = true;}

        clear(str);
            base16(palin,str);
        if(palindrome_2(str,0,str.size()-1) ==true) {cout <<" 16";
        result = true;
        }
        }
        //cout << "result : " << result <<endl;
       else if(result == false) cout <<"Number "<<palin<< " is not palindrom";
        cout << endl;
        
    }

   
}
We say that a number is a palindrom if it is the same when read from left to right or from right to left. For example, the number 75457 is a palindrom.

Of course, the property depends on the basis in which the number is represented. The number 17 is not a palindrom in base 10, but its representation in base 2 (10001) is a palindrom.

The objective of this problem is to verify if a set of given numbers are palindroms in any basis from 2 to 16.

Input

Several integer numbers comprise the input. Each number 0 < n < 50000 is given in decimal basis in a separate line. The input ends with a zero.

Output

Your program must print the message `Number i is palindrom in basis' where i is the given number, followed by the basis where the representation of the number is a palindrom. The leftmost digit of a number in any basis must be nonzero.

If the number is not a palindrom in any basis between 2 and 16, your program must print the message `Number i is not palindrom'.

Sample Input

17
19
0
Sample Output

Number 17 is palindrom in basis 2 4 16
Number 19 is not palindrom
Did you have a question? What kinds of errors were you getting?

oh idk this is acm problem

i thought everything is correct but online judge did not

accept it

probably something i missing... i am not sure

i am keep checking different numbers
Last edited on
Topic archived. No new replies allowed.