All Your Base

Rate this post

My solution for the "All Your Base" task of Google Code Jam 2009 Round1C (in C language):

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <regex.h>

int d[256];
int c[256];

main() {
  char str[4096];
  int t, i, numd, base, pc, code;
  size_t len, T;
  long long otv, k;

  fgets(str, sizeof(str), stdin);
  sscanf(str, "%d", &T);

  for (t = 0; t < T; t++) {
    fgets(str, sizeof(str), stdin);

    bzero(d, sizeof(d));
    bzero(c, sizeof(c));
    len = strlen(str);

    numd = 0;
    for (i = 0; i < len; i++) {
      if ((str[i] < '0' || str[i] > '9') && (str[i] < 'a' || str[i] > 'z')) continue;
      if (d[str[i]]) continue;
      switch(numd) {
      case 0: code = 1; break;
      case 1: code = 0; break;
      default: code = numd; break;
      c[str[i]] = code;
    if (numd == 1) numd++;

    otv = 0;
    for(i = 0; i < len; i++) {
      if ((str[i] < '0' || str[i] > '9') && (str[i] < 'a' || str[i] > 'z')) continue;
      otv *= (long long)numd;
      otv += (long long)c[str[i]];

    printf("Case #%d: %lld\n", t + 1, otv);

  return 0;

0 thoughts on “All Your Base

  1. DavidFloub

    Do you feel the pain of acid reflux? Do you feel a fire inside your chest? Are you miserable? Are you ready for the issues to stop? Continue reading to find out how. Keep reading to learn to control acid reflux for good and to end the misery for good.

    You may need to balance out hydrochloric acid amounts in your body if you want to reduce acid reflux and its symptoms. You can do this, for instance, by using sea salt rather than table salt. Sea salt has chloride and minerals that are good for the stomach and prevent acid.

  2. Vickie Figueroa

    Hello my name is Deanna Brady and I just wanted to send you a quick message here instead of calling you. I discovered your All Your Base – Founds website and noticed you could have a lot more hits. I have found that the key to running a successful website is making sure the visitors you are getting are interested in your website topic. There is a company that you can get keyword targeted visitors from and they let you try their service for free for 7 days. I managed to get over 300 targeted visitors to day to my site.

Leave a Reply

Your email address will not be published. Required fields are marked *