コード例 #1
0
ファイル: tmpi_rank.c プロジェクト: Shtkddud123/New
// Gets the rank of the recv_data, which is of type datatype. The rank is returned
// in send_data and is of type datatype.
int TMPI_Rank(void *send_data, void *recv_data, MPI_Datatype datatype, MPI_Comm comm) {
  // Check base cases first - Only support MPI_INT and MPI_FLOAT for this function.
  if (datatype != MPI_INT && datatype != MPI_FLOAT) {
    return MPI_ERR_TYPE;
  }

  int comm_size, comm_rank;
  MPI_Comm_size(comm, &comm_size);
  MPI_Comm_rank(comm, &comm_rank);

  // To calculate the rank, we must gather the numbers to one process, sort the numbers, and then
  // scatter the resulting rank values. Start by gathering the numbers on process 0 of comm.
  void *gathered_numbers = gather_numbers_to_root(send_data, datatype, comm);

  // Get the ranks of each process
  int *ranks = NULL;
  if (comm_rank == 0) {
    ranks = get_ranks(gathered_numbers, comm_size, datatype);
  }

  // Scatter the rank results
  MPI_Scatter(ranks, 1, MPI_INT, recv_data, 1, MPI_INT, 0, comm);

  // Do clean up
  if (comm_rank == 0) {
    free(gathered_numbers);
    free(ranks);
  }
}
コード例 #2
0
ファイル: hand.c プロジェクト: Risto-Stevcev/c-video-poker
num_pairs
find_pairs (Hand *self)
{
    int pairs[MAX_PAIR] = { 0, 0 };
    int ranks[MAX_HAND];
    get_ranks(&ranks, &self->cards);

    int i;
    int j = 0;
    for (i = 1; i < MAX_HAND; i++) {   
        if (ranks[i-1] == ranks[i])
            pairs[j]++;
        else if (j == 0 && pairs[j] != 0)
            j++;
    }

    if (pairs[0] == 1 && pairs[1] == 0)
        return one_pair;
    else if (pairs[0] == 1 && pairs[1] == 1)
        return two_pair;
    else if ((pairs[0] == 2 && pairs[1] == 1) || 
             (pairs[0] == 1 && pairs[1] == 2))
        return full_house;
    else if (pairs[0] == 2 && pairs[1] == 0)
        return three_kind;
    else if (pairs[0] == 3 && pairs[1] == 0)
        return four_kind;
    else
        return no_pair;
}
コード例 #3
0
ファイル: hand.c プロジェクト: Risto-Stevcev/c-video-poker
int
high_card (Hand *self)
{
    int ranks[MAX_HAND];
    get_ranks(&ranks, &self->cards);

    return ranks[MAX_HAND - 1];   
}
コード例 #4
0
ファイル: hand.c プロジェクト: Risto-Stevcev/c-video-poker
bool
is_royal_flush (Hand *self)
{
    int ranks[MAX_HAND];
    get_ranks(&ranks, &self->cards);

    return self->is_straight(self) && self->is_flush(self)
        && ranks[0] == 10 && ranks[MAX_HAND-1] == 14;
}
コード例 #5
0
ファイル: 10315.c プロジェクト: dtompkins/uva-online-judge
int main(void) {
  int i;
  char val, suit;
  int bmajor, bminor, wmajor, wminor;

  init_cards();

  while(1) {
    for (i=0; i < 5; i++) {
      if (scanf(" %c%c", &val, &suit) != 2) {
        exit(0);
      }
      black_values[i] = card_values[val];
      black_suits[i] = card_suits[suit];
    }
    for (i=0; i < 5; i++) {
      if (scanf(" %c%c", &val, &suit) != 2) {
        exit(0);
      }
      white_values[i] = card_values[val];
      white_suits[i] = card_suits[suit];
    }
    qsort(black_values, 5, sizeof(int), compare);
    qsort(black_suits, 5, sizeof(int), compare);
    qsort(white_values, 5, sizeof(int), compare);
    qsort(white_suits, 5, sizeof(int), compare);

    get_ranks(black_values, black_suits, &bmajor, &bminor);
    get_ranks(white_values, white_suits, &wmajor, &wminor);

    if (wmajor > bmajor) {
      printf("White wins.\n");
    } else if (bmajor > wmajor) {
      printf("Black wins.\n");
    } else if (wminor > bminor) {
      printf("White wins.\n");
    } else if (bminor > wminor) {
      printf("Black wins.\n");
    } else {
      printf("Tie.\n");
    }
  }
}
コード例 #6
0
ファイル: hand.c プロジェクト: Risto-Stevcev/c-video-poker
bool
is_straight (Hand *self)
{
    int ranks[MAX_HAND];
    get_ranks(&ranks, &self->cards);

    int i;
    for (i = 1; i < MAX_HAND; i++) { 
        if (ranks[i-1] + 1 != ranks[i])
            return false;
    }
    return true;
}