Esempio n. 1
0
long long pay(int n)
{
	static long long pay_arr[100];

	if(n<0)
		return 0;

	if(pay_arr[n] !=0)
		return pay_arr[n];

	if(n==0)
		return 1;

	return pay_arr[n] = pay(n-1) + pay(n-2) + pay(n-5);// +pay(n-10)+pay(n-20)+ pay(n-50);
}
Esempio n. 2
0
string Payment::toString(SYSTEMTIME &T) // образование итоговой строки
{
    string str="Стаж: ";
    char buf[10];
    ostringstream ost;

    itoa(experience(T), buf, 10);
    str += buf;
    str += "\nНадбавка: ";
    ost << markup;
    str += ost.str();
    str += "\nНачисленная сумма: ";
    ost.str("");
    ost << accrual;
    str += ost.str();
    str += "\nУдерженная сумма: ";
    ost.str("");
    ost << hold;
    str += ost.str();
    str += "\nНаччисленная зарплата: ";
    ost.str("");
    ost << pay();
    str += ost.str();
    return str;
}
Esempio n. 3
0
static int calc(coins *saving, int price, coins *payment)
{
  int total;
  int i500, i100, i50, i10;
  coins payment_work, saving_work, record = 
    { MAX_COIN, MAX_COIN, MAX_COIN, MAX_COIN };

  for (i500 = 0; i500 <= saving->y500; i500++) {
    for (i100 = 0; i100 <= saving->y100; i100++) {
      for (i50 = 0; i50 <= saving->y50; i50++) {
        for (i10 = 0; i10 <= saving->y10; i10++) {
          payment_work.y500 = i500;
          payment_work.y100 = i100;
          payment_work.y50 = i50;
          payment_work.y10 = i10;
          saving_work = *saving;
          if (!pay(price, &saving_work, &payment_work)) {
            if (total_weight(&record) > 
                total_weight(&saving_work)) {
              *payment = payment_work;
              record = saving_work;
            }
          }
        }
      }
    }
  }

  return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
	
	//从收银系统导入商品库存数据 
	struct set_t *products; //库存商品集合 
	struct sales_promotion *product_promotion; //优惠活动信息
	char shopping[] = "[\
				'ITEM00001-3',\
				'ITEM00002-2',\
				'ITEM00003-6'\
			]"; /*购物车商品*/
	
	
	struct set_t *shopping_set; //购物车商品集合
	
	shopping_set = set_new(100, compare_product, hashcode);
	//取得库存商品,打印小票时需要
	products = get_products();
	
	//取得优惠活动信息,结算时需要
	product_promotion = get_promotion();
    
	//取得购物车商品集合,结算时需要
    	prase_JSON_array(shopping, shopping_set, pack_cart); 
	 
	//结算
	pay(products, product_promotion, shopping_set);
	
	return 0;
}
Esempio n. 5
0
int main()
{
    int bills[6] = {1, 2, 5, 10, 20, 50};
    int money = 100;

    int result = pay(money, bills, 6);
    printf("%d\n", result);


}
Esempio n. 6
0
float Manager::output_pay (float hrswkd) {
	//Dynamic Memory Example, look into later
	//float *temp;
	//temp = new float;
	//*temp = ( *payrate * *hoursworked );
	
	return pay(hrswkd);
	
	//No point as this will never be reached
	//delete temp;
}
Esempio n. 7
0
/*       -1 if object could not be found (but was paid) */
static int
dopayobj(struct bill_x *bp)
{
	struct obj *obj;
	long ltmp;

	/* find the object on one of the lists */
	obj = bp_to_obj(bp);

	if (!obj) {
		impossible("Shopkeeper administration out of order.");
		setpaid();	/* be nice to the player */
		return (0);
	}

	if (!obj->unpaid && !bp->useup) {
		impossible("Paid object on bill??");
		return (1);
	}
	obj->unpaid = 0;
	ltmp = bp->price * bp->bquan;
	if (ANGRY(shopkeeper))
		ltmp += ltmp / 3;
	if (u.ugold < ltmp) {
		pline("You don't have gold enough to pay %s.",
		      doname(obj));
		obj->unpaid = 1;
		return (0);
	}
	pay(ltmp, shopkeeper);
	pline("You bought %s for %ld gold piece%s.",
	      doname(obj), ltmp, plur(ltmp));
	if (bp->useup) {
		struct obj *otmp = billobjs;
		if (obj == billobjs)
			billobjs = obj->nobj;
		else {
			while (otmp && otmp->nobj != obj)
				otmp = otmp->nobj;
			if (otmp)
				otmp->nobj = obj->nobj;
			else
				pline("Error in shopkeeper administration.");
		}
		free(obj);
	}
	return (1);
}
Esempio n. 8
0
/*       -1 if object could not be found (but was paid) */
static Short dopayobj(bill_t *bp)
{
  obj_t *obj;
  Long ltmp;

  /* find the object on one of the lists */
  obj = bp_to_obj(bp);

  if (!obj) {
    message("BUG: Shopkeeper administration out of order.");
    setpaid();	/* be nice to the player */
    return 0;
  }

  if (!(obj->bitflags & O_IS_UNPAID) && !bp->useup) {
    message("BUG: Paid object on bill??");
    return 1;
  }
  obj->bitflags &= ~O_IS_UNPAID;
  ltmp = bp->price * bp->bquantity;
  if (ANGRY(shopkeeper)) ltmp += ltmp/3;
  if (you.ugold < ltmp) {
    StrPrintF(ScratchBuffer, "You don't have gold enough to pay %s.",
	      doname(obj));
    message(ScratchBuffer);
    obj->bitflags |= O_IS_UNPAID;
    return 0;
  }
  pay(ltmp, shopkeeper);
  StrPrintF(ScratchBuffer, "You bought %s for %ld gold piece%s",
	    doname(obj), ltmp, (ltmp == 1 ? "." : "s."));
  message(ScratchBuffer);
  if (bp->useup) {
    obj_t *otmp = billobjs;
    if (obj == billobjs)
      billobjs = obj->nobj;
    else {
      while (otmp && otmp->nobj != obj) otmp = otmp->nobj;
      if (otmp) otmp->nobj = obj->nobj;
      else message("BUG: Error in shopkeeper administration.");
    }
    free_me((VoidPtr) obj);
  }
  return 1;
}
Esempio n. 9
0
void database::pay_workers( share_type& budget )
{
//   ilog("Processing payroll! Available budget is ${b}", ("b", budget));
   vector<std::reference_wrapper<const worker_object>> active_workers;
   get_index_type<worker_index>().inspect_all_objects([this, &active_workers](const object& o) {
      const worker_object& w = static_cast<const worker_object&>(o);
      auto now = _pending_block.timestamp;
      if( w.is_active(now) && w.approving_stake(_vote_tally_buffer) > 0 )
         active_workers.emplace_back(w);
   });

   // worker with more votes is preferred
   // if two workers exactly tie for votes, worker with lower ID is preferred
   std::sort(active_workers.begin(), active_workers.end(), [this](const worker_object& wa, const worker_object& wb) {
      share_type wa_vote = wa.approving_stake(_vote_tally_buffer);
      share_type wb_vote = wb.approving_stake(_vote_tally_buffer);
      if( wa_vote != wb_vote )
         return wa_vote > wb_vote;
      return wa.id < wb.id;
   });

   for( int i = 0; i < active_workers.size() && budget > 0; ++i )
   {
      const worker_object& active_worker = active_workers[i];
      share_type requested_pay = active_worker.daily_pay;
      if( _pending_block.timestamp - get_dynamic_global_properties().last_budget_time != fc::days(1) )
      {
         fc::uint128 pay(requested_pay.value);
         pay *= (_pending_block.timestamp - get_dynamic_global_properties().last_budget_time).count();
         pay /= fc::days(1).count();
         requested_pay = pay.to_uint64();
      }

      share_type actual_pay = std::min(budget, requested_pay);
      //ilog(" ==> Paying ${a} to worker ${w}", ("w", active_worker.id)("a", actual_pay));
      modify(active_worker, [&](worker_object& w) {
         w.worker.visit(worker_pay_visitor(actual_pay, *this));
      });

      budget -= actual_pay;
   }
}
Esempio n. 10
0
int pay(int money, int bills[], int n)
{
    int count = 0;
    int t;

    if (n == 1) {
        if (money % bills[0] == 0) {
            return 1;
        } else {
            return 0;
        }
    }

    t = money / bills[n - 1];
    for (int i = 0; i <= t; i++) {
        count += pay(money -bills[n - 1] * i, bills, n - 1);
    }

    return count;
}
Esempio n. 11
0
// Pay
vector<ZZ> Buyer::pay(const string& key) {
	return pay(CommonFunctions::vectorize<string>(key));
}
Esempio n. 12
0
void
subfrombill(struct obj *obj)
{
	long ltmp;
	int tmp;
	struct obj *otmp;
	struct bill_x *bp;

	if (!inshop() ||
	    (u.ux == ESHK(shopkeeper)->shk.x && u.uy == ESHK(shopkeeper)->shk.y) ||
	    (u.ux == ESHK(shopkeeper)->shd.x && u.uy == ESHK(shopkeeper)->shd.y))
		return;
	if ((bp = onbill(obj)) != NULL) {
		obj->unpaid = 0;
		if (bp->bquan > obj->quan) {
			otmp = newobj(0);
			*otmp = *obj;
			bp->bo_id = otmp->o_id = flags.ident++;
			otmp->quan = (bp->bquan -= obj->quan);
			otmp->owt = 0;	/* superfluous */
			otmp->onamelth = 0;
			bp->useup = 1;
			otmp->nobj = billobjs;
			billobjs = otmp;
			return;
		}
		ESHK(shopkeeper)->billct--;
		*bp = bill[ESHK(shopkeeper)->billct];
		return;
	}
	if (obj->unpaid) {
		pline("%s didn't notice.", Monnam(shopkeeper));
		obj->unpaid = 0;
		return;		/* %% */
	}
	/* he dropped something of his own - probably wants to sell it */
	if (shopkeeper->msleep || shopkeeper->mfroz ||
	    inroom(shopkeeper->mx, shopkeeper->my) != ESHK(shopkeeper)->shoproom)
		return;
	if (ESHK(shopkeeper)->billct == BILLSZ ||
	    ((tmp = shtypes[rooms[ESHK(shopkeeper)->shoproom].rtype - 8]) &&
	     tmp != obj->olet) || strchr("_0", obj->olet)) {
		pline("%s seems not interested.", Monnam(shopkeeper));
		return;
	}
	ltmp = getprice(obj) * obj->quan;
	if (ANGRY(shopkeeper)) {
		ltmp /= 3;
		NOTANGRY(shopkeeper) = 1;
	} else
		ltmp /= 2;
	if (ESHK(shopkeeper)->robbed) {
		if ((ESHK(shopkeeper)->robbed -= ltmp) < 0)
			ESHK(shopkeeper)->robbed = 0;
		pline("Thank you for your contribution to restock this recently plundered shop.");
		return;
	}
	if (ltmp > shopkeeper->mgold)
		ltmp = shopkeeper->mgold;
	pay(-ltmp, shopkeeper);
	if (!ltmp)
		pline("%s gladly accepts %s but cannot pay you at present.",
		      Monnam(shopkeeper), doname(obj));
	else
		pline("You sold %s and got %ld gold piece%s.", doname(obj), ltmp,
		      plur(ltmp));
}
Esempio n. 13
0
int
dopay(void)
{
	long ltmp;
	struct bill_x *bp;
	struct monst *shkp;
	int pass, tmp;

	multi = 0;
	inshop();
	for (shkp = fmon; shkp; shkp = shkp->nmon)
		if (shkp->isshk && dist(shkp->mx, shkp->my) < 3)
			break;
	if (!shkp && u.uinshop &&
	    inroom(shopkeeper->mx, shopkeeper->my) == ESHK(shopkeeper)->shoproom)
		shkp = shopkeeper;

	if (!shkp) {
		pline("There is nobody here to receive your payment.");
		return (0);
	}
	ltmp = ESHK(shkp)->robbed;
	if (shkp != shopkeeper && NOTANGRY(shkp)) {
		if (!ltmp)
			pline("You do not owe %s anything.", monnam(shkp));
		else if (!u.ugold)
			pline("You have no money.");
		else {
			long ugold = u.ugold;

			if (u.ugold > ltmp) {
				pline("You give %s the %ld gold pieces he asked for.",
				    monnam(shkp), ltmp);
				pay(ltmp, shkp);
			} else {
				pline("You give %s all your gold.", monnam(shkp));
				pay(u.ugold, shkp);
			}
			if (ugold < ltmp / 2)
				pline("Unfortunately, he doesn't look satisfied.");
			else {
				ESHK(shkp)->robbed = 0;
				ESHK(shkp)->following = 0;
				if (ESHK(shkp)->shoplevel != dlevel) {
					/* For convenience's sake, let him disappear */
					shkp->minvent = 0;	/* %% */
					shkp->mgold = 0;
					mondead(shkp);
				}
			}
		}
		return (1);
	}

	if (!ESHK(shkp)->billct) {
		pline("You do not owe %s anything.", monnam(shkp));
		if (!u.ugold) {
			pline("Moreover, you have no money.");
			return (1);
		}
		if (ESHK(shkp)->robbed) {
#define	min(a, b)	((a < b) ? a : b)
			pline("But since his shop has been robbed recently,");
			pline("you %srepay %s's expenses.",
			    (u.ugold < ESHK(shkp)->robbed) ? "partially " : "",
			    monnam(shkp));
			pay(min(u.ugold, ESHK(shkp)->robbed), shkp);
			ESHK(shkp)->robbed = 0;
			return (1);
		}
		if (ANGRY(shkp)) {
			pline("But in order to appease %s,",
			      amonnam(shkp, "angry"));
			if (u.ugold >= 1000) {
				ltmp = 1000;
				pline(" you give him 1000 gold pieces.");
			} else {
				ltmp = u.ugold;
				pline(" you give him all your money.");
			}
			pay(ltmp, shkp);
			if (strncmp(ESHK(shkp)->customer, plname, PL_NSIZ)
			    || rn2(3)) {
				pline("%s calms down.", Monnam(shkp));
				NOTANGRY(shkp) = 1;
			} else
				pline("%s is as angry as ever.", Monnam(shkp));
		}
		return (1);
	}
	if (shkp != shopkeeper) {
		impossible("dopay: not to shopkeeper?");
		if (shopkeeper)
			setpaid();
		return (0);
	}
	for (pass = 0; pass <= 1; pass++) {
		tmp = 0;
		while (tmp < ESHK(shopkeeper)->billct) {
			bp = &bill[tmp];
			if (!pass && !bp->useup) {
				tmp++;
				continue;
			}
			if (!dopayobj(bp))
				return (1);
			bill[tmp] = bill[--ESHK(shopkeeper)->billct];
		}
	}
	pline("Thank you for shopping in %s's %s store!",
	      shkname(shopkeeper),
	      shopnam[rooms[ESHK(shopkeeper)->shoproom].rtype - 8]);
	NOTANGRY(shopkeeper) = 1;
	return (1);
}
Esempio n. 14
0
void FenVente::BoutonValider()
{
	float somme=0.0;
	for(int i=0;i<liste->rowCount();i++)
	{
		somme+=liste->item(i,6)->text().toFloat();
	}
	FenPayement pay(somme); 
	pay.setValue(somme);
	if(pay.exec()==QDialog::Rejected)
	{
		return;
	}
	QSqlQuery req;
	req.prepare("INSERT INTO Ticket (client,prixb,prixc,prixd,num,date) VALUES (:cli,:b,:c,:d,:num,NOW())");
	req.bindValue(":cli",clients[curclient]);
	req.bindValue(":b",pay.Banque());
	req.bindValue(":c",pay.Cash());
	req.bindValue(":d",pay.Cheque());
	req.bindValue(":num",ui->spinBox_3->value());
	req.exec();
	req.prepare("SELECT id FROM Ticket WHERE num=:num AND DATE(date)=CURDATE() AND client=:cli");
	req.bindValue(":cli",clients[curclient]);
	req.bindValue(":num",ui->spinBox_3->value());
	req.exec();
	req.next();
	int idticket=req.value(0).toInt();
	for(int i=0,c=liste->rowCount();i<c;i++)
	{
		QString entete=liste->item(i)->text();
		if(entete=="A-")
		{
			req.prepare("SELECT id FROM Acompte WHERE client = :cli AND valeur= :mon AND datededuit='0000-00-00'");
			req.bindValue(":mon",-(liste->item(i,6)->text().toInt()));
			req.bindValue(":cli",clients[curclient]);
			req.exec();
			if(req.next())
			{
				int idacompte=req.value(0).toInt();
				req.prepare("UPDATE Acompte SET datededuit=CURDATE(),tickdeduit=:tic WHERE id=:id");
				req.bindValue(":id",idacompte);
				req.bindValue(":tic",idticket);
				req.exec();
			}
			else
			{
				QMessageBox::critical(this,"Erreur","Une déduction d'acompte n'a pu être correctement effectuée : l'acompte n'a pu être retrouvé");
			}
		}
		else if(entete=="A+")
		{
			req.prepare("INSERT INTO Acompte(client,valeur,dateintro,tickintro) VALUES (:cli,:mon,CURDATE(),:tic)");
			req.bindValue(":cli",clients[curclient]);
			req.bindValue(":mon",liste->item(i,6)->text().toInt());
			req.bindValue(":tic",idticket);
			req.exec();
		}
		else if(entete=="?")
		{
			req.prepare("INSERT INTO ventenonreconnue(Modele,NArticle,Coloris,Taille,Qt,Prix,Ticket) VALUES (:mod,:art,:col,:tai,:qt,:prix,:tic)");
			req.bindValue(":mod",liste->item(i,1)->text());
			req.bindValue(":art",liste->item(i,2)->text());
			req.bindValue(":col",liste->item(i,3)->text());
			req.bindValue(":tai",liste->item(i,4)->text());
			req.bindValue(":qt",liste->item(i,5)->text().toInt());
			req.bindValue(":prix",(liste->item(i,6)->text().toFloat())/(liste->item(i,5)->text().toInt()));
			req.bindValue(":tic",idticket);
			req.exec();
		}
		else
		{
			req.prepare("CALL vendre(:tic,:code,:qt,:prix)");
			req.bindValue(":tic",idticket);
			req.bindValue(":code",liste->item(i,0)->text().toInt());
			req.bindValue(":qt",liste->item(i,5)->text().toInt());
			req.bindValue(":prix",liste->item(i,6)->text().toFloat());
			req.exec();
		}
	}
	system((QDir::homePath()+QString("/Gestion/ElixiP 0 %1").arg(idticket)).toStdString().c_str());
	req.exec("SELECT id,nom,prenom, adresse, codepostal,localite FROM Client ORDER BY nom,prenom,adresse");
	ui->clientComboBox->clear();
	ui->clientComboBox->addItem("DIVERS");
	clients.clear();
	clients.push_back(1);
	while(req.next())
	{
		if(req.value(0).toInt()!=1)
		{
			ui->clientComboBox->addItem(QString("%1 %2 %3 %4 %5").arg(req.value(1).toString()).arg(req.value(2).toString()).arg(req.value(3).toString()).arg(req.value(4).toString()).arg(req.value(5).toString()));
			clients.push_back(req.value(0).toInt());
		}
	}
	req.exec("CALL TicNum(CURDATE())");
	req.next();
	ui->spinBox_3->setValue(req.value(0).toInt());
	liste->removeRows(0,liste->rowCount());
	listecompte=0;
}
Esempio n. 15
0
void CashboxWindow::create_calc_and_options()
{
    outputRow = new QHBoxLayout();
    calcOptionRow = new QHBoxLayout();
    zeroRow = new QHBoxLayout();
    calcLayout = new QVBoxLayout();
    outputNum = new QLineEdit("");
    outputNum->setEnabled(false);
    outputRow->addWidget(outputNum);
    numRows[2] = new QHBoxLayout();
    num7 = new QPushButton("7");
    numRows[2]->addWidget(num7);
    connect(num7,SIGNAL(clicked()),SLOT(addToOutput()));
    num8 = new QPushButton("8");
    numRows[2]->addWidget(num8);
    connect(num8,SIGNAL(clicked()),SLOT(addToOutput()));
    num9 = new QPushButton("9");
    numRows[2]->addWidget(num9);
    connect(num9,SIGNAL(clicked()),SLOT(addToOutput()));
    numRows[1] = new QHBoxLayout();
    num4 = new QPushButton("4");
    numRows[1]->addWidget(num4);
    connect(num4,SIGNAL(clicked()),SLOT(addToOutput()));
    num5 = new QPushButton("5");
    numRows[1]->addWidget(num5);
    connect(num5,SIGNAL(clicked()),SLOT(addToOutput()));
    num6 = new QPushButton("6");
    numRows[1]->addWidget(num6);
    connect(num6,SIGNAL(clicked()),SLOT(addToOutput()));
    numRows[0] = new QHBoxLayout();
    num1 = new QPushButton("1");
    numRows[0]->addWidget(num1);
    connect(num1,SIGNAL(clicked()),SLOT(addToOutput()));
    num2 = new QPushButton("2");
    numRows[0]->addWidget(num2);
    connect(num2,SIGNAL(clicked()),SLOT(addToOutput()));
    num3 = new QPushButton("3");
    numRows[0]->addWidget(num3);
    connect(num3,SIGNAL(clicked()),SLOT(addToOutput()));
    num0 = new QPushButton("0");
    zeroRow->addWidget(num0);
    connect(num0,SIGNAL(clicked()),SLOT(addToOutput()));
    btPoint = new QPushButton(".");
    calcOptionRow->addWidget(btPoint);
    connect(btPoint,SIGNAL(clicked()),SLOT(addToOutput()));
    btDeleteAll = new QPushButton("(X)");
    calcOptionRow->addWidget(btDeleteAll);
    connect(btDeleteAll,SIGNAL(clicked()),SLOT(deleteOutput()));
    btDeleteLast = new QPushButton("<-");
    calcOptionRow->addWidget(btDeleteLast);
    connect(btDeleteLast,SIGNAL(clicked()),SLOT(deleLastFromOutput()));
    btCalc = new QPushButton("CALC");
    calcOptionRow->addWidget(btCalc);
    connect(btCalc,SIGNAL(clicked()),SLOT(pay()));

    //Add all Layouts to one Calc-Layout
    calcLayout->addLayout(outputRow);
    calcLayout->addLayout(numRows[2]);
    calcLayout->addLayout(numRows[1]);
    calcLayout->addLayout(numRows[0]);
    calcLayout->addLayout(zeroRow);
    calcLayout->addLayout(calcOptionRow);
    option_Layout = new QVBoxLayout();
    lbOptions = new QLabel("<b>Options:</b>");
    lbFreeSpace1 = new QLabel("");
    btRemoveSelectedItem = new QPushButton("Remove Selected Item");
    connect(btRemoveSelectedItem, SIGNAL(clicked()),SLOT(delete_selected_table_row()));
    btDone = new QPushButton("NEXT CUSTOMER");
    connect(btDone,SIGNAL(clicked()),SLOT(nextCustomer()));
    option_Layout->addWidget(lbOptions);
    option_Layout->addWidget(btRemoveSelectedItem);
    option_Layout->addWidget(btDone);
    option_Layout->addWidget(lbFreeSpace1);
    option_Layout->addWidget(lbFreeSpace1);
    total_calcLayout = new QHBoxLayout();
    total_calcLayout->addLayout(calcLayout);
    total_calcLayout->addLayout(option_Layout);
    total_Layout->addLayout(top_Layout);
    total_Layout->addLayout(total_calcLayout);
}
Esempio n. 16
0
void subfrombill(struct obj *obj)
{
  Long ltmp;
  Short tmp;
  obj_t *otmp;
  bill_t *bp;
  eshk_t *eshk = (shopkeeper ? ESHK(shopkeeper) : NULL);
  if (!inshop() ||
      (you.ux == eshk->shk.x && you.uy == eshk->shk.y) ||
      (you.ux == eshk->shd.x && you.uy == eshk->shd.y))
    return;
  if ((bp = onbill(obj)) != 0) {
    obj->bitflags &= ~O_IS_UNPAID;
    if (bp->bquantity > obj->quantity) {
      otmp = (obj_t *) md_malloc(sizeof(obj_t));// newobj(0);
      *otmp = *obj;
      bp->bo_id = otmp->o_id = flags.ident++;
      otmp->quantity = (bp->bquantity -= obj->quantity);
      otmp->owt = 0;	/* superfluous */
      do_name(otmp, NULL); // otmp->onamelth = 0; // Undo name (if any)
      bp->useup = true;
      otmp->nobj = billobjs;
      billobjs = otmp;
      return;
    }
    eshk->billct--;
    *bp = bill[eshk->billct];
    return;
  }
  if (obj->bitflags & O_IS_UNPAID) {
    StrPrintF(ScratchBuffer, "%s didn't notice.", Monnam(shopkeeper));
    message(ScratchBuffer);
    obj->bitflags &= ~O_IS_UNPAID;
    return;		/* %% */
  }
  /* he dropped something of his own - probably wants to sell it */
  if ((shopkeeper->bitflags & (M_IS_ASLEEP | M_IS_FROZEN)) ||
      inroom(shopkeeper->mx,shopkeeper->my) != eshk->shoproom)
    return;
  if (eshk->billct == BILLSZ ||
      ((tmp = shtypes[rooms[eshk->shoproom].rtype-8]) && tmp != obj->olet) ||
      StrChr("_0", obj->olet)) {
    StrPrintF(ScratchBuffer, "%s seems not interested.", Monnam(shopkeeper));
    message(ScratchBuffer);
    return;
  }
  ltmp = getprice(obj) * obj->quantity;
  if (ANGRY(shopkeeper)) {
    ltmp /= 3;
    shopkeeper->bitflags |= M_IS_PEACEFUL; // NOTANGRY(shopkeeper) = 1;
  } else   ltmp /= 2;
  if (eshk->robbed) {
    if ((eshk->robbed -= ltmp) < 0)
      eshk->robbed = 0;
    message("Thank you for your contribution to restock this recently plundered shop.");
    return;
  }
  if (ltmp > shopkeeper->mgold)
    ltmp = shopkeeper->mgold;
  pay(-ltmp, shopkeeper);
  if (!ltmp)
    StrPrintF(ScratchBuffer,
	      "%s gladly accepts %s but cannot pay you at present.",
	      Monnam(shopkeeper), doname(obj));
  else
    StrPrintF(ScratchBuffer,
	      "You sold %s and got %ld gold piece%s",
	      doname(obj), ltmp, (ltmp == 1 ? "." : "s."));
  message(ScratchBuffer);
}
Esempio n. 17
0
// What does the return value indicate??
Boolean dopay()
{
  Long ltmp;
  bill_t *bp;
  monst_t *shkp;
  Short pass, tmp;

  multi = 0;
  inshop();
  for (shkp = fmon ; shkp ; shkp = shkp->nmon)
    if ((shkp->bitflags & M_IS_SHOPKEEPER) && dist(shkp->mx,shkp->my) < 3)
      break;
  if (!shkp && you.uinshop &&
      inroom(shopkeeper->mx,shopkeeper->my) == ESHK(shopkeeper)->shoproom)
    shkp = shopkeeper;

  if (!shkp) {
    message("There is nobody here to receive your payment.");
    return false;
  }
  ltmp = ESHK(shkp)->robbed;
  if (shkp != shopkeeper && NOTANGRY(shkp)) {
    if (!ltmp) {
      StrPrintF(ScratchBuffer, "You do not owe %s anything.", monnam(shkp));
      message(ScratchBuffer);
    } else
      if (!you.ugold) {
	message("You have no money.");
      } else {
	Long ugold = you.ugold;

	if (you.ugold > ltmp) {
	  StrPrintF(ScratchBuffer,
		    "You give %s the %ld gold pieces he asked for.",
		    monnam(shkp), ltmp);
	  message(ScratchBuffer);
	  pay(ltmp, shkp);
	} else {
	  StrPrintF(ScratchBuffer, "You give %s all your gold.", monnam(shkp));
	  message(ScratchBuffer);
	  pay(you.ugold, shkp);
	}
	if (ugold < ltmp/2) {
	  message("Unfortunately, he doesn't look satisfied.");
	} else {
	  ESHK(shkp)->robbed = 0;
	  ESHK(shkp)->following = false;
	  if (ESHK(shkp)->shoplevel != dlevel) {
	    /* For convenience's sake, let him disappear */
	    shkp->minvent = NULL;	/* %% */ // xxx leak?
	    shkp->mgold = 0;
	    mondead(shkp);
	  }
	}
      }
    return true;
  }
		
  if (!ESHK(shkp)->billct) {
    StrPrintF(ScratchBuffer, "You do not owe %s anything.", monnam(shkp));
    message(ScratchBuffer);
    if (!you.ugold) {
      message("Moreover, you have no money.");
      return true;
    }
    if (ESHK(shkp)->robbed) {
      message("But since his shop has been robbed recently,");
      StrPrintF(ScratchBuffer, "you%srepay %s's expenses.",
		(you.ugold < ESHK(shkp)->robbed) ? " partially " : " ",
		monnam(shkp));
      message(ScratchBuffer);
      pay(min(you.ugold, ESHK(shkp)->robbed), shkp);
      ESHK(shkp)->robbed = 0;
      return true;
    }
    if (ANGRY(shkp)) {
      StrPrintF(ScratchBuffer, "But in order to appease %s,",
		amonnam(shkp, "angry"));
      message(ScratchBuffer);
      if (you.ugold >= 1000) {
	ltmp = 1000;
	message(" you give him 1000 gold pieces.");
      } else {
	ltmp = you.ugold;
	message(" you give him all your money.");
      }
      pay(ltmp, shkp);
      if (StrNCompare(ESHK(shkp)->customer, plname, PL_NSIZ)
	  || rund(3)){
	StrPrintF(ScratchBuffer, "%s calms down.", Monnam(shkp));
	message(ScratchBuffer);
	shkp->bitflags |= M_IS_PEACEFUL; // NOTANGRY(shopkeeper) = 1;
      } else {
	StrPrintF(ScratchBuffer, "%s is as angry as ever.",
		  Monnam(shkp));
	message(ScratchBuffer);
      }
    }
    return true;
  }
  if (shkp != shopkeeper) {
    message("BUG: dopay: not to shopkeeper?");
    if (shopkeeper) setpaid();
    return false;
  }
  for (pass = 0 ; pass <= 1 ; pass++) {
    tmp = 0;
    while (tmp < ESHK(shopkeeper)->billct) {
      bp = &bill[tmp];
      if (!pass && !bp->useup) {
	tmp++;
	continue;
      }
      if (!dopayobj(bp)) return true;
      bill[tmp] = bill[--ESHK(shopkeeper)->billct];
    }
  }
  StrPrintF(ScratchBuffer, "Thank you for shopping in %s's %s store!",
	    shkname(shopkeeper),
	    shopnam[rooms[ESHK(shopkeeper)->shoproom].rtype - 8]);
  shopkeeper->bitflags |= M_IS_PEACEFUL; // NOTANGRY(shopkeeper) = 1;
  return true;
}
Esempio n. 18
0
int main()
{
  coins saving, payment;
  char buf[256];

  saving.y500 = 0;
  saving.y100 = 2;
  saving.y50 = 1;
  saving.y10 = 1;
  calc(&saving, 160, &payment);
  assert(payment.y10 == 1);
  assert(payment.y50 == 1);
  assert(payment.y100 == 1);
  assert(payment.y500 == 0);

  saving.y500 = 4;
  saving.y100 = 3;
  saving.y50 = 2;
  saving.y10 = 1;
  assert(total(&saving) == 2410);

  exchange(2380, &saving);
  assert(saving.y500 == 4);
  assert(saving.y100 == 3);
  assert(saving.y50 == 1);
  assert(saving.y10 == 3);

  payment.y500 = 1;
  payment.y100 = 0;
  payment.y50 = 0;
  payment.y10 = 0;
  assert(pay(490, &saving, &payment) == 0);
  assert(saving.y500 == 3);
  assert(saving.y100 == 3);
  assert(saving.y50 == 1);
  assert(saving.y10 == 4);

  {
    int nums[4];
    char buf[256];
    strncpy(buf, "0 1 2", sizeof(buf));
    assert(parse(buf, 4, nums) == 3);
    assert(nums[0] == 0);
    assert(nums[1] == 1);
    assert(nums[2] == 2);
    strncpy(buf, "0 1 2 4", sizeof(buf));
    assert(parse(buf, 4, nums) == -1);
  }

  while (fgets(buf, sizeof(buf), stdin) != NULL) {
    int price;
    int nums[4 + 1];

    sscanf(buf, "%d", &price);
    if (!price) break;

    if (fgets(buf, sizeof(buf), stdin) == NULL) break;

    assert(parse(buf, sizeof(nums) / sizeof(nums[0]), nums) == 4);

    saving.y10 = nums[0];
    saving.y50 = nums[1];
    saving.y100 = nums[2];
    saving.y500 = nums[3];

    calc(&saving, price, &payment);

    if (payment.y10 > 0) printf("10 %d\n", payment.y10);
    if (payment.y50 > 0) printf("50 %d\n", payment.y50);
    if (payment.y100 > 0) printf("100 %d\n", payment.y100);
    if (payment.y500 > 0) printf("500 %d\n", payment.y500);
    printf("\n");
  }

  return 0;
}