Informatika gyűjtemény

Egy szinttel feljebb shoppingplan.pas

2004050607080910

NézetNyomtat

shoppingplan.pas (Vissza)
Az alábbi letöltési lehetőségek közül választhatsz: (segítség)
Karakterkódolás:
Sortörés:
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: us-ascii
Méret: 3 KB
{$B-} 
PROGRAM ShoppingPlan;
CONST
    tid = 'small';
    inputFile = 'D-'+tid+'-practice.in';
    outputFile = 'D-'+tid+'-practice.out';
    maxItems = 15;
    maxStores = 50;
    maxFull = (1 SHL maxItems) - 1;
    infinitePrice = 1E9;

VAR
    num_items, num_stores, price_of_gas: INTEGER;
    item_names: ARRAY [1..maxItems] OF STRING; {a bevasarlolistan levo termekek nevei}
    item_perishable: ARRAY [1..maxItems] OF BOOLEAN; {item_perishable[i]: romlando-e az i. termek}
    store_x : ARRAY [0..maxStores] OF INTEGER; {store_x[i]: az i. bolt x koordinataja}
    store_y : ARRAY [0..maxStores] OF INTEGER; {store_y[i]: az i. bolt y koordinataja}
    store_prices : ARRAY [0..maxStores, 1..maxItems] OF INTEGER; {store_prices[i][j]: a j. termek ara az i. boltban, 0 ha nem kaphato}
    store_codes: ARRAY [0..maxStores] OF INTEGER; {store_prices[i] j. bitje 1, ha a j. termek kaphato az i. boltban}
    


FUNCTION Solve(): DOUBLE;
BEGIN
END; {Solve}

{Ha line szimpla szokozokkel vagy kettospontokkal elvalasztott stringek sorozata, akkor ez a fuggveny a pos pozicion kezdodot,
es pos-t a kovetkezo string elejere allitja.}
FUNCTION NextToken(line: STRING; VAR pos: INTEGER): STRING;
VAR
    pos0, len: INTEGER;
BEGIN
    pos0:= pos;
    len := Length(line);
    WHILE (pos <= len) AND (line[pos] <> ' ') AND (line[pos] <> ':') DO INC(pos);
    NextToken := Copy(line, pos0, pos-pos0);
    INC(pos);
END; {NextToken}

PROCEDURE TestCase(id: INTEGER; VAR fin, fout: Text);
VAR
    i, j, pos, len: INTEGER;
    s, item_price, item_name: STRING;
    errCode: WORD;
    solution: DOUBLE;
BEGIN
    ReadLn(fin, num_items, num_stores, price_of_gas);
{   WriteLn('case= ', id, ' num_items= ', num_items, ' num_stores= ', num_stores, ' price_of_gas= ', price_of_gas);}
    ReadLn(fin, s);
    len := Length(s);
    pos := 1;
    FOR i:= 1 TO num_items DO
    BEGIN
        item_names[i] := NextToken(s, pos);
        item_perishable[i] := item_names[i][ Length(item_names[i]) ] = '!';
        IF item_perishable[i] THEN item_names[i] := Copy(item_names[i], 1, Length(item_names[i])-1);
    END;
    FOR i := 0 TO num_stores DO
    BEGIN
        store_codes[i]:=0;
        FOR j:= 1 TO num_items DO store_prices[i][j] := 0;
        store_x[i]:= 0; store_y[i]:=0;
        IF (= 0) THEN CONTINUE;
        Read(fin, store_x[i], store_y[i]);
        {WriteLn('store_x[',i,']= ', store_x[i],' store_y[',i,']= ', store_y[i]);}
        ReadLn(fin, s);
        len := Length(s);
        pos := 2; {elso szokoz atugrasa}
        WHILE (pos <= len) DO
        BEGIN {termeknev:ar par beolvasasa kovetkezik}
            item_name := NextToken(s, pos); {kovetkezo termeknev}
            item_price := NextToken(s, pos); {a termek ara}
            {termek sorszamanak a kikeresese nev alapjan:}
            j := 1; WHILE (<= num_items) AND (item_names[j] <> item_name) DO INC(j);
            store_codes[i] := store_codes[i] OR ( 1 SHL (j-1) );
            Val(item_price, store_prices[i][j], errCode);
{           WriteLn(item_name,' --> store_prices[',i,'][', j, '] = ', store_prices[i][j] );}
        END;
    END;
    solution:= Solve();
    WriteLn('Case #',id,': ', solution:0:7);
    WriteLn(fout, 'Case #',id,': ', solution:0:7);
END; {TestCase}

PROCEDURE Main();
VAR
    fin, fout: Text;
    i, N: INTEGER;
BEGIN
    Assign(fin, inputFile);
    Assign(fout, outputFile);
    Reset(fin);
    Rewrite(fout);
    ReadLn(fin, N);
    FOR i:= 1 TO N DO
    BEGIN
        TestCase(i, fin, fout);
    END;
    Close(fin);
    Close(fout);
END; {Main}

BEGIN
    Main();
END.
(Vissza)