codeblocks - Different answers on different platforms for c++ -
hi ran code on codechef's ide , on codeblocks. got answer different answers: 1001 codeblock 818(correct one) codechef ide. please help!.
code snipplet : http://pastie.org/10223010
#include <iostream> #include <string> #include<sstream> #include<cmath> using namespace std; int palin(int n); int main() { int i,t; int n; cin>>t; for(i=0;i<t;i++){ cin>>n; palin(n); while(1){ n++; if(palin(n)==1){ cout<<n<<endl; break; } } } return 0; } int palin(int n){ int len=0; int m=0; int dum=n; while(n!=0){ n=n/10; len++; } n=dum; while(n!=0){ m=m+((pow(10,(len-1)))*(n%10)); n=n/10; len--; } if(dum==m) return 1; else return 0; }
problem statement :http://www.codechef.com/problems/palin/
don't use pow() function use float arithmetic , gives wrong answer integer variables
instead use custom power function integer variable, like
int pw(int a, int b){ int ans = 1; while(b--){ ans *= a; } return ans; }
Comments
Post a Comment