J
Joona I Palaste
Ben Pfaff said:Joona I Palaste said:Alexander Bartolich said:begin followup to Joona I Palaste:
OK, I bid $300.Cool.
So the financial damage of this piece of code is $50 per line.
OTOH I have some doubts whether the OP can compile, run, format,
present and explain it.#include <limits.h>
#include <stdio.h>
#include <ctype.h>
int main(){int c;int n[1<<CHAR_BIT]={0};while(EOF!=(c=getchar()))
n[tolower(c)]++;printf("a=%d b=%d c=%d\n",n['a'],n['b'],n['c']);
return 0;}
Here's my version. 254 characters.
#include <stdio.h>
#include <ctype.h>
int a[3]={0};int count(void){int c=getchar();return c==EOF?0(tolower(c)=='a'?
a[0]++:tolower(c)=='b'?a[1]++:tolower(c)=='c'?a[2]++:0),count());}int
main(void){return count(),printf("%d %d %d\n",a[0],a[1],a[2]),0;}
My entry (184 characters):
int main(){int getchar(),printf(const char*,...),tolower();int c,n[4]={0};while
((c=tolower(getchar()))>=0)n[c=='a'?0:c=='b'?1:c=='c'?2:3]++;printf("a=%d,b=%d\
,c=%d\n",*n,n[1],n[2]);}
Well, I have to say your code fits into smaller space, but you not only
use a two-statement function, one of those statements is a while loop.
My version only used one-statement functions, with no loops or if
statements. Now if I could only somehow remove the need for the local
variable c. (Don't suggest making it global...)