Example #1
0
int sumDigits(int** grid, int* sum, int rows, int cols, int digits)
{
    int r,c, digit, carry, cbegin, cend, rend;
    
    digit = digits-1;
    carry = 0;
    cend = cols-1;
    cbegin = cend-digits;
    
    for(c=cend; c>cbegin; c--)
    {
        carry += sumDown(grid, 0, c, rows);
        sum[digit--] = carry%10;
        carry /= 10;
    }
    
    return carry;
}
Example #2
0
void eval(char *cmd) {
  if (cmd[0] == '\0')
    return;
  char *af = strchr(cmd, ' ');
  if (af != NULL)
    *af = '\0';
  if (strcmp(cmd, "init") == 0) {
    int r, c;
    if (af != NULL)
      if (sscanf(af + 1, "%d %d", &r, &c) == 2) {
        init_matrix(r, c);
        return;
      }

    wprintw(work_wnd, "Usage: init nrows ncolumns\n");
    return;
  }
  if (strcmp(cmd, "randomize") == 0) {
    int l, h;
    if (af != NULL)
      if (sscanf(af + 1, "%d %d", &l, &h) == 2) {
        randomize(l, h);
        return;
      }

    wprintw(work_wnd, "Usage: randomize min max\n");
    return;
  }
  if (strcmp(cmd, "mutate") == 0) {
    int r, c, nv;
    if (af != NULL)
      if (sscanf(af + 1, "%d %d %d", &r, &c, &nv) == 3) {
        mutate(r, c, nv);
        return;
      }
    wprintw(work_wnd, "Usage: mutate row column new_value\n");
    return;
  }
  if (strcmp(cmd, "null") == 0) {
    tonull();
    return;
  }
  if (strcmp(cmd, "sumDown") == 0) {
    sumDown();
    return;
  }
  if (strcmp(cmd, "reflectSide") == 0) {
    transposeSide();
    return;
  }
  if (strcmp(cmd, "rotate") == 0) {
    rotate();
    return;
  }
  if (strcmp(cmd, "flipH") == 0) {
    flipH();
    return;
  }
  if (strcmp(cmd, "avg") == 0) {
    avg();
    return;
  }
  if (strcmp(cmd, "feswap") == 0) {
    feswap();
    return;
  }
  if (strcmp(cmd, "leswap") == 0) {
    leswap();
    return;
  }
  if (strcmp(cmd, "ecswap") == 0) {
    ecswap();
    return;
  }
  if (strcmp(cmd, "q") == 0) {
    finish();
    exit(EXIT_SUCCESS);
    return;
  }
  if (strcmp(cmd, "sumC") == 0) {
    size_t column;
    if (af != NULL)
      if (sscanf(af + 1, "%zu", &column) == 1) {
        sumColumn(column);
        return;
      }
    wprintw(work_wnd, "Usage: sumC column\n");
    return;
  }
  print_help();
}