I have tried 3 problems so far in code chef, all of which get wrong answer tag upon submission. What is up with that? Kindly help.
The latest problem : FLOW007 Problem - CodeChef
My solution : - #include <stdio.h> #include <math.h>
int main(void) {
int n, m, a, b, c, d, nd, T, t, i = 1, j, l, s = 0, k = 0, z;
printf("Enter the number of times you wanna do this shit.");
scanf("%d", &T);
for(c=1; c<=T; c++)
{
printf("\nEnter testcase #%d's number. ", i);
scanf("%d", &n);
if(-10<n && n<10)
{
k = 1;
printf("\nNumber of digits = %d", k);
}
else
{
for(i=1; k!=n; i++)
{
t = pow(10,i);
k = n % t;
}
nd = i - 1;
printf("\nThe number of digits = %d", nd);
}
for(j=nd, m=0; j>=1; j--, m++)
{
a = pow(10,j);
b = pow(10, j-1);
k = n%a;
l = n%b;
d = pow(10, m);
z = ((k-l)/b)*d;
s = s + z;
}
printf("\nThe reversed number is = %d.", s);
}
return 0;
Dude! please don’t print “enter the number” and all that kinds of stuff
Here is how we need to Implement
int main(void) {
int n, m, a, b, c, d, nd, T, t, i = 1, j, l, s = 0, k = 0, z;
scanf("%d", &T);
for(c=1; c<=T; c++)
{
char a[100000];
scanf("%s",a);
for(int i=strlen(a)-1;i>=0;i--)
{
print("%c",a[i]):
}
}
Bear in mind that your submitted entry for a CodeChef problem is not being looked at by a person; a computer program is assessing your output for matching exactly to the requirements. So no input prompts, no descriptive text around the results, and make sure text outputs if any are exactly as given, including matching upper and lower case.
The part of programming you can work on here is about making the algorithms work, and (eventually, hopefully) work efficiently. The part of programming concerned with giving good supporting information to users, validating values etc. isn’t really covered here, and establishing an accurate specification is mostly just a matter of reading the problem very carefully (and occasionally checking the sample output to clarify).
Yeah, Thanks! My bad Actually I didn’t look into ending with zeroes case, if we want to do it with strings there is no string data type in C so I took 10^5 bytes we can still do it with int also
For Code with strings: