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.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
36 bytes
In this problem, the key observation is that the ASCII value of each letter is equal to its position, offset by . A basic implementation might read the character via scanf()
and output its ASCII value, minus :
#include<stdio.h>
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 -byte solution:
#include<stdio.h>
c;main(){scanf("%c",&c);printf("%d\n",c-64);}
Also, scanf()
is rather long to simply fetch the first character. We can instead use getchar()
, which does exactly that. This saves us another bytes:
#include<stdio.h>
main(){printf("%d\n",getchar()-64);}
Finally, to obtain the -byte solution, we realize that the #include
header is unnecessary, as C allows the declaration of most library functions without needing their headers:
main(){printf("%d\n",getchar()-64);}
Comments