2011/12/21 Vikram Gaur <[email protected]>:
> shorter and better i think :)
@Vikram Gaur:
Your code is doing a lot of useless computation.
You need neither to compute the length of the string nor to copy it.
So I'm not sure it's really "better".
Starting back at my code, you may optimize a bit more :
int compute(char* s)
{
int n = 0;
char p = s;
for (; *s; s++)
n += *s;
n -= '0' * ((int)s - (int)p) / sizeof(*s);
return (n);
}
And you seem to like the main function so...
int main(int argc, char** argv)
{
if (argc != 2)
return (1);
printf("%d\n", compute(argv[1]));
return (0);
}
Happy? :)
--
Jérémie MARGUERIE
Student at EPITA, France
"Many snake oil algorithms claim unbreakability by claiming to be a OTP.
Pseudo-OTPs give pseudo-security" -- Peter Gutmann
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.