All pastes #640220 Raw Edit

Untitled

public text v1 · immutable
#640220 ·published 2007-07-31 06:45 UTC
rendered paste body
#include<string>
#include<iostream>
#include<vector>
using namespace std;

static int baseb=10,countb=0;
static bool check;
bool palin(int);int base(int,int);

int main()
{
	int n,s,count=0;

	cin>>n;cin>>s;

	//check for palindromes from s onwards
	for(int i=s;i<10000;i++)
	{
		if(count==(n-1))
		return(0);

		countb=0;check=false;baseb=10;

		if(palin(i))
		{
			cout<<s<<endl;
			count++;
		}
	}

}

bool palin(int no)
{
	char temp[5];string str;int i,j;bool flag=true;

	//convert no to string
	sprintf(temp,"%d",no); str=(string)temp; 
	
	//check for palindrome
	for(i=0,j=str.size()-1;i<str.size();i++,j--)
	{
		if(str[i]!=str[j])
		{ flag=false;break;}
	}

	/*cout<<"no "<<no<<"check "<<check<<"flag "<<flag<<"countb "<<countb<<"base "<<baseb<<endl;*/
	//if palindrome and count==2 return true for the no
	if(flag==true)
	{ 
	countb++;
	if(countb==1)
	return(true);
	}
	else if(check==false);
	{
		check=true;
		for(int i=9;i>=2;i--)
		{
			bool x;baseb=i;
			x=palin(base(no,i));
		}
	}

	
		
	return(false);

}

int base(int no,int i)
{
	cout<<"no "<<no;
	string temp; int ret;char x;
	while(no!=0)
	{
		cout<<no%i<<endl;
		x=no%i+'0';
		temp=temp+x;
		no=no/i;
	
	}
	
	reverse(temp.begin(),temp.end());
	sscanf(temp.c_str(),"%d",&ret);
	/*cout<<"i "<<i<<"temp "<<temp<<endl;*/
	return(ret);
}