void kd::onTextChange(const QString& text) { QString tmpstr = text; struct GoodsSearch search; //int price = findGood(tmpstr, &search); if( findGood(tmpstr, &search) ) { if (search.found_item->data(3,0).toString().compare("root") == 0) { QTextStream(&tmpstr) << " " << search.count << tr(" pcs.") << " = " << search.total_price << tr(" rub."); } } item_suggest->setText(item_suggest->fontMetrics().elidedText( tmpstr, Qt::ElideLeft, item_suggest->width() )); return; }
int main(){ scanf("%d", &n); arr = new int[n]; goodArr = new bool[n]; for(int i=0;i<n;i++){ scanf("%d ", &arr[i]); goodArr[i] = false; } std::sort(arr, arr+n); for(int i=1;i<n;i++){ if(findGood(i)) break; } int cnt = 0; for(int i=0;i<n;i++){ if(goodArr[i]) cnt++; } printf("%d", cnt); return 0; }
void kd::onAddButtonPress(void) { QString tmpstr = item_input->text(); QString tmpstr1; struct GoodsSearch search; //int price = findGood(tmpstr); if(tmpstr.startsWith("*") || tmpstr.startsWith(";")) // close check or close with discount { if( tmpstr.startsWith(";") ) // if close with discount { QString tmpstr2; QString cardnum = tmpstr.mid(1, tmpstr.length() - 2); // Get card number = input string - 1 char from both ends tmpstr2 = QString::fromUtf8( cards->value( cardnum, "" ).toString().toAscii() ); // Get ini record for card if (tmpstr2.length() > 0) { QString cardholder = tmpstr2.left(tmpstr2.indexOf(':')); int discount = tmpstr2.mid(tmpstr2.indexOf(':') + 1).toInt(); int dsc_val = totalprice / 100 * discount; // rounding if ((dsc_val % 10) != 0) if((dsc_val % 10) < 5) dsc_val -= dsc_val % 10; else dsc_val += 10 - (dsc_val % 10); totalprice -= dsc_val; // Discount itself QTextStream(&tmpstr1) << "Discount" << ";"<< "Discount "<< discount << "%, card " << cardnum << " " << cardholder << ";" << 1 << ";-" << dsc_val; added_items->append( tmpstr1 ); logger->writeLine( tmpstr1 ); } } tmpstr1 = tr("Close check"); QTextStream(&tmpstr1) << ";" << totalprice; added_items->append( tmpstr1 ); logger->writeLine( tmpstr1 ); totalprice = 0; item_input->clear(); updateCurrentTotal(); } if( findGood(tmpstr, &search) ) { if(search.found_item->data(3,0).toString().compare("root") == 0) { QTextStream(&tmpstr1) << item_input->text() << " - "<< tmpstr << search.count << tr(" pcs.") << " = " << search.total_price << tr(" rub."); added_items->append(tmpstr1); tmpstr = tmpstr.left(tmpstr.length()-3); tmpstr1 = ""; QTextStream(&tmpstr1) << item_input->text() << ";"<< tmpstr << ";" << search.count << ";" << search.total_price; logger->writeLine(tmpstr1); totalprice += search.total_price; item_input->clear(); updateCurrentTotal(); } else { if(search.found_item->data(3,0).toString().compare("launcher") == 0) { if( QProcess::startDetached(search.found_item->data(1,0).toString()) ) QTextStream(&tmpstr1) << search.found_item->data(0,0).toString() << tr(" launched"); else QTextStream(&tmpstr1) << tr("Failed to launch ") << search.found_item->data(0,0).toString(); QTextStream(&tmpstr1) << search.found_item->data(0,0).toString() << tr(" launched"); added_items->append(tmpstr1); logger->writeLine(tmpstr1); } } } return; }