Skip to content

Instantly share code, notes, and snippets.

@TheoKlein
Last active August 11, 2016 15:20
Show Gist options
  • Select an option

  • Save TheoKlein/50a8b7493eb9b0f2d38950dae15d5c60 to your computer and use it in GitHub Desktop.

Select an option

Save TheoKlein/50a8b7493eb9b0f2d38950dae15d5c60 to your computer and use it in GitHub Desktop.
ZeroJudge a536
#include <iostream>
using namespace std;
class Soda{
public:
Soda(int = 0 , int = 0 , int = 0);
void Exchange();
int getEmpty();
int getExchange();
int getDrinked();
private:
int drinked;
int empty;
int exchange;
};
int main (){
int n;
cin >> n;
while(n-- != 0){
int e, f, c;
cin >> e >> f >> c;
Soda Tim(e, f, c);
while(Tim.getEmpty() >= Tim.getExchange()){
Tim.Exchange();
}
cout << Tim.getDrinked() << endl;
}
}
Soda::Soda(int e, int f, int c){
drinked = 0;
empty = e + f;
exchange = c;
}
void Soda::Exchange(){
if(empty >= exchange){
int temp = empty / exchange;
if(empty % exchange != 0){
drinked += temp;
empty %= exchange;
empty += temp;
}else{
drinked += temp;
empty = temp;
}
}
}
int Soda::getEmpty(){
return empty;
}
int Soda::getExchange(){
return exchange;
}
int Soda::getDrinked(){
return drinked;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment