fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int hash(char const * string) {
  5. int h = 0;
  6. for (; *string; ++string) {
  7. int index = tolower(*string) - 'a' + 1;
  8. if ((index > 0) && (index < 27)) {
  9. h += index;
  10. }
  11. }
  12. return h;
  13. }
  14.  
  15. int main(void) {
  16. printf ("%d %d\n", hash("aaa"), hash("ab"));
  17. return 0;
  18. }
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
3 3