int main() { int x1,y1,x2,y2,x3,y3,gcd; char c; //scanf("%d",&x1); while(scanf("%d/%d%c%d/%d",&x1,&y1,&c,&x2,&y2)!=EOF) { if(c=='-')x2=-x2; x3=x1*y2+x2*y1; y3=y1*y2; int k=x3%y3; if(k==0){printf("%d\n",x3/y3);continue;} gcd=god(x3,y3); x3/=gcd; y3/=gcd; printf("%d/%d\n",x3,y3); } return 0; }
int main(void) { int* p; p = init(); show(p); while(1) { printf("move which: "); int moved; scanf("%d", &moved); if(moved == 100) { god(p); } else { swap_with_empty(p, moved); } moved = 0; } }
void inl_draft_select(int n) { struct player *j, *k = me; /* j: pick-ee, k: pick-er */ if ((n < 0) || (n > MAXPLAYER)) return; j = &players[n]; switch (j->p_inl_draft) { case INL_DRAFT_OFF : /* not involved */ break; case INL_DRAFT_CAPTAIN_UP : /* captain with right to select */ break; case INL_DRAFT_CAPTAIN_DOWN : /* captain without right to select */ if (k->p_inl_draft == INL_DRAFT_CAPTAIN_UP) { /* captain fingers fellow captain */ /* meaning: pass */ if (inl_draft_next(k)) { pmessage(0, MALL, "GOD->ALL", "%s passes this draft pick.", k->p_mapchars); } /* TODO: this can result in an imbalance */ } break; case INL_DRAFT_MOVING_TO_POOL : /* in transit to pool */ case INL_DRAFT_POOLED : /* in pool of players to be chosen */ if (k->p_inl_draft == INL_DRAFT_CAPTAIN_UP) { /* captain fingers a pool player */ /* meaning: pool player is picked, next captain to pick */ if (!j->p_inl_captain) { if (inl_draft_next(k)) { inl_draft_pick(j, k); } } } else if (k->p_inl_draft == INL_DRAFT_PICKED_SELECTOR) { /* selector fingers a pool player */ /* meaning: pool player is picked, next captain to pick */ k = inl_draft_pick_to_captain(me); if (k == NULL) { pmessage(0, MALL, "GOD->ALL", "Draft error, %s has no captain.", me->p_mapchars); return; } if (k->p_inl_draft != INL_DRAFT_CAPTAIN_UP) { pmessage(0, MALL, "GOD->ALL", "Draft error, pick by %s ignored because captain is not up.", me->p_mapchars); return; } if (!j->p_inl_captain) { if (inl_draft_next(k)) { inl_draft_pick(j, k); } } } else if (k->p_inl_draft == INL_DRAFT_PICKED) { /* non-captain pick fingers a pool player */ /* meaning: team signaling to captain their preference */ /* TODO: distort pool position according to how many fingerings */ } break; case INL_DRAFT_MOVING_TO_PICK : /* has been chosen, in transit to team */ case INL_DRAFT_PICKED : /* has been chosen by a captain */ if (k->p_inl_draft == INL_DRAFT_CAPTAIN_UP || k->p_inl_draft == INL_DRAFT_CAPTAIN_DOWN) { /* captain fingers a picked player */ /* meaning: delegation of pick duty */ if (j->p_team == k->p_team) { j->p_inl_draft = INL_DRAFT_PICKED_SELECTOR; god(j->p_no, "Draft selector, your captain has chosen you to pick."); } } break; case INL_DRAFT_PICKED_SELECTOR: if (k->p_inl_draft == INL_DRAFT_CAPTAIN_UP || k->p_inl_draft == INL_DRAFT_CAPTAIN_DOWN) { /* captain fingers a selector */ /* meaning: cancel delegation of pick duty */ if (j->p_team == k->p_team) { j->p_inl_draft = INL_DRAFT_PICKED; god(j->p_no, "Draft selector, your captain has withdrawn your duty to pick."); } } break; } }
/* highlight the captain who is waiting */ static void inl_draft_highlight_down(struct player *k) { getship(&k->p_ship, SCOUT); god(k->p_no, "Draft captain, the other captain has the pick, standby."); }
/* highlight the captain with the up */ static void inl_draft_highlight_up(struct player *k) { getship(&k->p_ship, BATTLESHIP); god(k->p_no, "Draft captain, your turn to pick a player."); }
int do_vote(char *comm, struct message *mess, struct command_handler_2 *votes, int num) { int what = 0; int player = -1; register int i; register struct player *j; int pcount=0; /* Total players in game */ int vcount=0; /* Number who've voted recently */ int mflag = 0; int sendto = 0; int who; char nv[PV_TOTAL+1]; who = mess->m_from; if (players[who].p_status == POBSERV) { god(who, "Sorry, observers can't vote"); return 0; } if (votes[num].tag & C_PLAYER) { if ((what = getplayer(who, comm)) < 0) return 0; player = what; } what += votes[num].start; if (what >= PV_TOTAL) return 0; j = &players[who]; if ((j->voting[what] != 0) && (votes[num].frequency != 0)) { if ( (j->voting[what] + votes[num].frequency) > time(NULL) ) { godf(who,"Sorry, you can only use %s every %1.1f minutes", votes[num].command, votes[num].frequency / 60.0); return 0; } } j->voting[what] = time(NULL); /* Enter newest vote */ if (votes[num].tag & C_VC_TEAM) { sendto = players[who].p_team; mflag = MTEAM; } else if (votes[num].tag & C_VC_ALL) { sendto = 0; mflag = MALL; } else { ERROR(1,("Unrecognized message flag in do_vote() for %s\n", comm)); return 0; } if (!strncmp(comm, "EJECT", 5) && (who == player)) { god(who, "Sorry, you can't eject yourself."); return 0; } nv[0] = '\0'; for (i=0, j = &players[i]; i < MAXPLAYER; i++, j++) { /*Skip free slots and robots */ if ( (j->p_status == PFREE) || (j->p_flags & PFROBOT)) continue; /*Also skip players that are not on the same team if team flag is set*/ if ((votes[num].tag & C_VC_TEAM) && (j->p_team != players[who].p_team)) continue; /* Also skip observers */ if (j->p_status == POBSERV) continue; pcount++; /* Did a player vote expire? */ if ((j->voting[what] > 0) && ((votes[num].expiretime == 0) || (j->voting[what] + votes[num].expiretime > time(NULL)))) { vcount++; } else { strcat(nv, j->p_mapchars); strcat(nv, " "); } } pmessage(sendto, mflag, addr_mess(sendto,mflag), "%s has voted to %s. %d player%s (of %d) %s voted.", players[who].p_mapchars, comm, vcount, vcount==1 ? "":"s", pcount, vcount==1 ? "has":"have"); /* The Votes Passes */ if ( (vcount >= votes[num].minpass) && ( ((pcount < (2*vcount)) && (votes[num].tag & C_VC_ALL)) || ((votes[num].tag & C_VC_TEAM) && (pcount/2 + 1 <= vcount)) )) { pmessage(sendto, mflag, addr_mess(sendto,mflag), "The motion %s passes", comm); /* Reset the Votes for this item since it passed */ for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) j->voting[what] = -1; if (votes[num].tag & C_PLAYER) (*votes[num].handler)(who, player, mflag, sendto); else (*votes[num].handler)(who, mflag, sendto); return 1; } else { /* if (votes[num].tag & C_VC_TEAM) i = pcount - vcount - 1; else */ i = pcount/2 + 1 - vcount; if (i < (votes[num].minpass - vcount)) i = votes[num].minpass - vcount; pmessage(sendto, mflag, addr_mess(sendto, mflag), "Still need %d more vote%s, from %s", i, (i==1 ? "":"s"), nv); return 0; } }