백준 1362
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
class Pet
{
public:
int weight;
int fit;
int sn = 1;
void Scenario()
{
std::string str1;
std::string str2;
char behav;
int work;
int cnt = 0;
while (true)
{
std::cin >> str1>>str2;
if (str1 == "0"&&str2=="0")
return;
if (str1 == "#"&&str2=="0")
{
Happiness();
cnt = 0;
sn++;
continue;
}
if (cnt == 0)
{
weight = stoi(str2);
fit = stoi(str1);
cnt++;
}
else
{
if (IsDead())
continue;
if (str1 == "E")
weight-=stoi(str2);
else
weight+=stoi(str2);
}
}
}
void Happiness()
{
if (IsDead())
{
std::cout <<sn<< " RIP" << std::endl;
return;
}
if (weight > fit / 2 && weight < fit * 2)
std::cout <<sn <<" :-)" << std::endl;
else
std::cout << sn<<" :-(" << std::endl;
}
bool IsDead()
{
if (weight <= 0)
return true;
return false;
}
};
int main()
{
Pet p;
p.Scenario();
}