2480번 - 주사위 세개
#include
using namespace std;
int main()
{
int money = 0;
int a, b, c = 0;
srand(time(NULL));
int dice1 = (rand() % 6) + 1;
int dice2 = (rand() % 6) + 1;
int dice3 = (rand() % 6) + 1;
if (dice1 == dice2 && dice1 == dice3 && dice2 == dice3) {
money = 10000 + (dice1 * 1000);
}
else if (dice1 == dice2 || dice2 == dice3 || dice1 == dice3) {
if (dice1 == dice2 && dice1 != dice3) {
money = (dice1 * 100) + 1000;
else if (dice1 == dice3 && dice1 != dice2) {
else {
money = (dice2 * 100) + 1000;
int max = dice1;
if (dice2 > max) {
max = dice2;
if (dice3 > max) {
max = dice3;
money = max * 100;
cout << dice1 << dice2 << dice3 << endl;
cout << money << endl;
return 0;
결과는 맞게 나오는데...
문제 풀이는 입력을 받고, 각 입력에 대한 정답을 출력하는 방식으로 이루어집니다. 따라서 입력 데이터는 이 코드처럼 랜덤으로 마음대로 생성하면 되는 게 아니라, 입력 스트림(stdin)을 통해 주어지는 것을 받아서 처리해야 합니다.
댓글을 작성하려면 로그인해야 합니다.
wddn1541 2년 전
#include
#include
#include
using namespace std;
int main()
{
int money = 0;
int a, b, c = 0;
srand(time(NULL));
int dice1 = (rand() % 6) + 1;
int dice2 = (rand() % 6) + 1;
int dice3 = (rand() % 6) + 1;
if (dice1 == dice2 && dice1 == dice3 && dice2 == dice3) {
money = 10000 + (dice1 * 1000);
}
else if (dice1 == dice2 || dice2 == dice3 || dice1 == dice3) {
if (dice1 == dice2 && dice1 != dice3) {
money = (dice1 * 100) + 1000;
}
else if (dice1 == dice3 && dice1 != dice2) {
money = (dice1 * 100) + 1000;
}
else {
money = (dice2 * 100) + 1000;
}
}
else {
int max = dice1;
if (dice2 > max) {
max = dice2;
}
if (dice3 > max) {
max = dice3;
}
money = max * 100;
}
cout << dice1 << dice2 << dice3 << endl;
cout << money << endl;
return 0;
}
결과는 맞게 나오는데...