We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I did it using conversion to string, but now that I see your solution, yours is simpler and faster. I share mine anyways:
#include<stdio.h>#include<stdlib.h>intreversed(inta){charc,*ptr_b,*ptr_e;charbuff[12];intb;//Integer to stringsprintf(buff,"%d",a);//Reversing stringptr_b=buff;ptr_e=buff;while(*ptr_e){//Moving ptr_e to point the last char in the string++ptr_e;}--ptr_e;while(ptr_b<ptr_e){//Reversingc=*ptr_b;*ptr_b=*ptr_e;*ptr_e=c;++ptr_b;--ptr_e;}//String to integersscanf(buff,"%d",&b);returnb;}intmain(){inti,j,k,rev,diff,count=0;//Inputscanf("%d %d %d",&i,&j,&k);//Countingfor(intii=i;ii<=j;++ii){rev=reversed(ii);diff=abs(ii-rev);if(diff%k==0)++count;}//Outputprintf("%d\n",count);return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Days at the Movies
You are viewing a single comment's thread. Return to all comments →
I did it using conversion to string, but now that I see your solution, yours is simpler and faster. I share mine anyways: