Dual Palindromes


/*
ID: tausiq11
PROG: dualpal
LANG: C++
*/

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

char a [35];

bool is_palindrome (char a [])
{
    int len = strlen (a);

    for ( int i = 0; i < len / 2; i++ ) {
        if ( a [i] != a [len - 1 - i] )
            return false;
    }

    return true;
}

void convertion (int s, int base)
{
    int len = 0;

    while ( s ) {
        a [len++] = (s % base) + 48;
        s /= base;
    }

    a [len] = '';

    for ( int i = 0; i < len / 2; i++ )
        swap ( a [i], a [len - 1 - i]);
}

int main ()
{
    freopen ("dualpal.in", "r", stdin);
	freopen ("dualpal.out", "w", stdout);

    int N, S;

    cin >> N >> S;

    while ( N ) {

        S++;
        int count = 0;

        for ( int i = 2; i < 11; i++ ) {

            convertion (S, i);

            if ( is_palindrome (a) )
            count++;

            if ( count == 2 ) {
                cout << S << endl;
                i = 11;
                N--;
            }
        }
    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s