#include // We do use getchar and printf, so having prototypes of those handy will avoid compiler issues. #include // We do use the isspace macro/function, so we need the prototype for it as well. /** This program has been written by me for Daniel's Obfuscated-V contest (http://graphics.stanford.edu/~danielrh/vote.html) ** Counting votes is hard. If you spot a bug in this code, please send me an email at . ** However, according to my tests this is rock solid. I made a clear decision to use crystal clear indentation format ** as well as documenting the code as much as possible with comments. There is never too many comments. **/ int main() /* Let's go, start cranking! **/ { int c /* We are going to put the char we are reading in this variable. **/ ; unsigned i=0 /* Counter for Kerry **/ ,j=0 /* Counter for Bu$h **/ ,k=0 /* Counter for Nader **/ ,l=0 /* Counter for the other insignificant candidates **/ ; while(666) /* loop forever until you hit the goto. Yes, you read right, the goto. I just had to put a goto in there. **/ { switch(c=getchar()) /* read one character of the input and put it in the c variable. **/ { case'K' /* tally the count for Kerry, this is important: he may win. **/ : i=1+i /* just add one to the Kerry count, hold in the i variable. **/ ; break /* don't forget to 'break' otherwise you will endup counting a vote for a candidates to multiple ones incorrectly **/ ; break /* Actually, do it twice, just to be sure. **/ ; case'B' /* do the same for bushy boy, count his vote. Right this time, not like in Florida damn it. **/ : j=1+j /* more of the same **/ ; break /* see the break, well it is as important as the addition before because you don't want giving Bush's votes to Nader do you? **/ ; case 'N' /* for Nader, do the same, count his votes. **/ : k=l+k /* more of the same **/ ; break /* and the break. **/ ; case EOF /* This is the end of the file **/ : goto end /* just jump to the end label to print the results. **/ ; default /* Nader is not the only one candidate with no chances to win whatsoever. There is more! **/ : if(!isspace(c))l++ /* count them, but discard the weirdos who cannot vote. **/ ;} /* **/ ;} /* **/ ; end: /* The end is near! **/ ; printf("Kerry %u\n",i) /* Did you notice that 'Bush' is 4 char, when 'Kerry', 'Nader' and 'Other' are all 5 chars... **/ ; printf("Bush %u\n",j) /* do you think this is significant? Maybe people voted for him because it was easier to read and write? **/ ; printf("Nader %u\n",k) /* That the reason for his victory. I suggest the short name mandatory act, whereas everybody should be able to **/ ; printf("Other %u\n",l) /* pick his favorite 4 character name to designate himself in order to stop the persecution of people with long names. **/ ; return 0 /* I'll be "@!Zb". **/ ;} /* **/