Editorial for Lyndon's Golf Contest 1 P1 - As Easy As ABC

Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Dingledooper

36 bytes

In this problem, the key observation is that the ASCII value of each letter is equal to its position, offset by 64. A basic implementation might read the character via scanf() and output its ASCII value, minus 64:

int c;int main(){scanf("%c",&c);printf("%d\n",c-64);}

This is pretty concise, but we can do a lot better. Abusing C's implicit int rule allows us to remove the type declarations, at the cost of a few warnings. This yields a 63-byte solution:


Also, scanf() is rather long to simply fetch the first character. We can instead use getchar(), which does exactly that. This saves us another 9 bytes:


Finally, to obtain the 36-byte solution, we realize that the #include header is unnecessary, as C allows the declaration of most library functions without needing their headers:



There are no comments at the moment.