#include<stdio.h>
int main()
{
unsigned int t,inp;
scanf("%u",&t);
while(t--)
{
unsigned int temp;
scanf("%u",&inp);
temp = inp?1+(inp/26):0;
inp=inp+temp;
while(inp--)
{
printf("%c",'a'+(inp%26));
}
printf("\n");
}
return 0;
}
What’s wrong with my code ?
Please help me.
- This code seems to be incorrect
temp = inp?1+(inp/26):0;
inp=inp+temp;
try this instead, see if this works
int temp1=inp;
temp = (inp/25)?(inp/25):0;
inp=inp+temp;
temp=(temp1%25)?1:0;
inp=inp+temp;
- also using int is enough, there is no need for unsigned int
if still there is wrong answer, let me know.
1 Like
what’s the difference between your code and mine ?
Please tell me, Cause both give the same answers I think.
Your logic is correct. Thank you.
But could you specify why my logic is wrong ?
no they do not give the same answer
try these test cases
t=5
k=53 52 51 50 49
1 Like
I understood myself. Thank you
we are dividing by 25 because a string with 25 positions(as stated in the problem) can be represented by a string of 26 characters.
Suppose,
if 1<=k<=25 we need k+1 characters
if 25<k<=50 we need k+(1)+(1)( +1 for first 25 (k/25=1)and other +1 for remaining characters as k%25!=0)
if 50<k<=75 we need k+(1+1)+(1)( +1 for first 25, +1 for next 25, and the last +1 for the reamaining characters as k%25!=0)
if k=50 we need k+(1+1)+(0)(+1 for first 25, +1 for next 25, last +0 as there are no remaining position we need to represent as k%25=0 )