백준 1362

Oak_Cassia·2022년 3월 10일

백준 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();
}
profile
https://velog.io/@oak_cassia/A-Game-Developers-Vision

0개의 댓글