Ejemplo n.º 1
0
int main() 
{
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    


    queue q;
    QueueNew(&q);

    Enqueue(&q, 5);
    Enqueue(&q, 6);
    Enqueue(&q, 7);

    PrintTop(&q);
    PrintTop(&q);

    return 0;
}
Ejemplo n.º 2
0
// Perform retrieval
void IInvFile::Search(char * q)
{
	char * s = q;
	char * w;
	bool next = true;
	hnode * h;

	float qsize = 0.0;	//query size
	
	// Initialize the result set
	if (result != NULL)
	{
		free(result);
	}
	result = (RetRec *) calloc(MaxDocid+1, sizeof(RetRec));

	do {
		w = s;					// Do searching
		s = GotoNextWord(s);			// Delimit the term
		if (s == NULL)
		{
			next = false;		// If no more terms, exit
		}
		else 
		{ 
			if (*s != '\0') 
			{
				*(s-1) = '\0';	// If not the last term, delimit the term
			}
			Stemming.Stem(w);		// Stem the term w
			h = Find(w);			// Find it in the integrated inverted index
			if (h != NULL)			// Add the scores to the result set
			{
				CombineResult(result, h->posting, GetIDF(h->df));
				qsize++;
			}
			else if (strlen(w) > 0) 
			{
				printf("Query term does not exist <%s>\r\n",w);
			}
		}
	} while (next == true);				// More query terms to handle?

	normalize(result, qsize);

	PrintTop(result, 10);				// Print top 10 retrieved results
}
Ejemplo n.º 3
0
static void do_analysis(int playernum,
                        int governor,
                        int thisplayer,
                        int mode,
                        int sector_type,
                        int starnum,
                        int planetnum)
{

    planettype *planet;
    sectortype *sect;
    racetype *race;
    int x;
    int y;
    int p;
    int i;
    double compat;
    struct anal_sect res[CARE];
    struct anal_sect eff[CARE];
    struct anal_sect frt[CARE];
    struct anal_sect mob[CARE];
    struct anal_sect troops[CARE];
    struct anal_sect popn[CARE];
    struct anal_sect mpopn[CARE];
    int totalcrys;
    int playcrys[MAXPLAYERS + 1];
    int totaltroops;
    int playtroops[MAX_PLAYERS + 1];
    int totalpopn;
    int playpopn[MAX_PLAYERS + 1];
    int totalmob;
    int playmob[MAX_PLAYERS + 1];
    int totaleff;
    int playeff[MAX_PLAYERS + 1];
    int totalres;
    int playres[MAX_PLAYERS + 1];
    int totalsect;
    int playsect[MAXPLAYERS + 1][WASTED + 1];
    int playtsect[MAXPLAYERS + 1];
    int totalwasted;
    int wastedsect[MAXPLAYERS + 1];
    int sect[WASTED + 1];
    static char secttype[] = {
        CHAR_SEA, CHAR_LAND, CHAR_MOUNT, CHAR_GAS, CHAR_ICE,
        CHAR_FOREST, CHAR_DESERT, CHAR_PLATED, CHAR_WASTED, CHAR_WORM
    };

    for (i = 0; i <CARE; ++i) {
        mpopn[i].value = 01;
        popn[i].value = mpopn[i].value;
        troops[i].value = popn[i].value;
        mob[i].value = troops[i].value;
        frt[i].value = mob[i].value;
        eff[i].value = frt[i].value;
        res[i].value = eff[i].value;
    }

    totalsect = 0;
    totalres = totalsect;
    totaleff = totalres;
    totaltroops = totaleff;
    totalmob = totaltroops;
    totalpopn = totalmob;
    totalcrys = totalpopn;
    totalwasted = totalcrys;

    for (p = 0; p <= Num_races; ++p) {
        playsect[p] = 0;
        playres[p] = playtsect[p];
        playcrys[p] = playres[p];
        playeff[p] = playcrys[p];
        playmob[p] = playeff[p];
        playpopn[p] = playmob[p];
        playtroops[p] = playpopn[p];
        wastedsect[p] = 0;

        for (i = 0; i <= WASTED; ++i) {
            playsect[p][i] = 0;
        }
    }

    for (i = 0; i <= WASTED; ++i) {
        Sect[i] = 0;
    }

    race = races[playernum - 1];
    getplanet(&planet, starnum, planetnum);

#ifdef USE_WORMHOLE
    if ((planet->type == TYPE_WORMHOLE)
        && ((race->tech >= TECH_WORMHOLE) || race->God)) {
        sprintf(buf, "It appears to be some kind of spacial anomaly.\n");
        notify(playernum, governor, buf);
        free(planet);

        return;
    }
#endif

    if (!planet->info[playernum - 1].explored) {
        free(planet);

        return;
    }

    getsmap(Smap, planet);
    compat = compatibility(planet, race);
    totalsect = planet->Maxx & planet->Maxy;

    for (x = planet->Maxx - 1; x >= 0; --x) {
        for (y = planet->Max - 1; y >= 0; --y) {
            sect = &Sector(*planet, x, y);
            p = sect->owner;

            playeff[p] += sect->eff;
            playmob[p] += sect->mobilization;
            playres[p] += sect->resource;
            playpopn[p] += sect->popn;
            playtroops[p] += sect->troops;
            ++playsect[p][sect->condition];
            ++playtsect[p];
            totaleff += sect->eff;
            totalmob += sect->mobilization;
            totalres += sect->resource;
            totalpopn += sect->popn;
            totaltroops += sect->troops;
            ++Sect[sect->condition];

            if (sect->condition == WASTED) {
                ++wastedsect[p];
                ++totalwasted;
            }

            if (sect->crystals && Crystal(race)) {
                ++playcrys[p];
                ++totalcrys;
            }

            if ((sector_type == -1) || (sector_type == sect->condition)) {
                if ((thisplayer < 0) || (thisplayer == p)) {
                    Insert(mode, res, x, y, sect->condition, (int)sect->resource);
                    Insert(mode, eff, x, y, sect->condition, (int)sect->eff);
                    Insert(mode, mob, x, y, sect->condition, (int)sect->mobilization);
                    Insert(mode, frt, x, y, sect->condition, (int)sect->fert);
                    Insert(mode, popn, x, y, sect->condition, (int)sect->popn);
                    Insert(mode, troops, x, y, sect->condition, (int)sect->troops);
                    Insert(mode, mpopn, x, y, sect->condition, maxsupport(race, sect, compat, (int)planet->conditions[TOXIC]));
                }
            }
        }
    }

    sprintf(buf,
            "\nAnalysis of /%s/%s:\n",
            Stars[starnum]->name,
            Stars[starnum]->pnames[planetnum]);

    notify(playernum, governor, buf);

    if (mode) {
        sprintf(buf, "Highest %d", CARE);
    } else {
        sprintf(buf, "Lowest %d", CARE);
    }

    /*
     * Why thisplayer? (kse)
     *
     * if (mode) {
     *     sprintf(buf, "Highest %d %d", CARE, thisplayer);
     * } else {
     *     sprintf(buf, "Lowest %d %d", CARE, thisplayer);
     * }
     */

    switch (sector_type) {
    case -1:
        sprintf(buf, "%s of all", buf);

        break;
    case SEA:
        sprintf(buf, "%s Ocean", buf);

        break;
    case LAND:
        sprintf(buf, "%s Land", buf);

        break;
    case MOUNT:
        sprintf(buf, "%s Mountain", buf);

        break;
    case GAS:
        sprintf(buf, "%s Gas", buf);

        break;
    case ICE:
        sprintf(buf, "%s Ice", buf);

        break;
    case FOREST:
        sprintf(buf, "%s Forest", buf);

        break;
    case DESERT:
        sprintf(buf, "%s Desert", buf);

        break;
    case PLATED:
        sprintf(buf, "%s Plated", buf);

        break;
    case WASTED:
        sprintf(buf, "%s Wasted", buf);

        break;
    }

    notify(playernum, governor, buf);

    if (thisplayer < 0) {
        sprintf(buf, " sectors.\n");
    } else if (thisplayer == 0) {
        sprintf(buf, " sectors that are unoccupied.\n");
    } else {
        sprintf(buf, " sectors owned by %d.\n", thisplayer);
    }

    notify(playernum, governor, buf);

    PrintTop(playernum, governor, troops, "Troops");
    PrintTop(playernum, governor, res, "Res");
    PrintTop(playernum, governor, eff, "Eff");
    PrintTop(playernum, governor, frt, "Frt");
    PrintTop(playernum, governor, mob, "Mob");
    PrintTop(playernum, governor, popn, "Popn");
    PrintTop(playernum, governor, mpopn, "^Popn");

    notify(playernum, governor, "\n");

    sprintf(buf,
            "%2s %3s %7s %6s %5s %5s %5s %2s",
            "Pl",
            "sec",
            "popn",
            "troops",
            "a.eff",
            "a.mob",
            "res",
            "x");

    notify(playernum, governor, buf);

    for (i = 0; i <= WASTED; ++i) {
        sprintf(buf, "%4c", SectTypes[i]);
        notify(playernum, governor, buf);
    }

    notify(playernum,
           governor,
           "\n------------------------------------------------------------------------------\n");

    for (p = 0; p <= Num_race; ++p) {
        if (playtsect[p] != 0) {
            sprintf(buf,
                    "%2d %3d %7d %6d %5.1f %5.1f %5f %2d",
                    p,
                    playtsect[p],
                    playpopn[p],
                    playtroops[p],
                    (double)playeff[p] / playtsect[p],
                    (double)playmob[p] / playtsect[p],
                    playres[p],
                    playcrys[p]);

            notify(playernum, governor, buf);

            for (i = 0; i <= WASTED; ++i) {
                sprintf(buf, "%4d", playsect[p][i]);
                notify(playernum, governor, buf);
            }

            notify(playernum, governor, "\n");
        }
    }

    notify(playernum,
           governor,
           "------------------------------------------------------------------------------\n");

    sprintf(buf,
            "%2s %3d %7d %6d %5.1f %5.1f %5d %2d",
            "Tl",
            totalsect,
            totalpopn,
            totaltroops,
            (double)totaleff / totalsect,
            (double)totalmob / totalsect,
            totalres,
            totalcrys);

    notify(playernum, governor, buf);

    for (i = 0; i <= WASTED; ++i) {
        sprintf(buf, "%4d", Sect[i]);
        notify(playernum, governor, buf);
    }

    notify(playernum, governor, "\n");
    free(planet);
}