코테용 문제풀이/백준

주사위 세개 풀이

doctscoder 2022. 12. 30. 23:42

문제 링크: https://www.acmicpc.net/problem/2480

백준 조건문 7단계 - 2480번 주사위 세개를 풀어보았다.

 

풀이: 값을 비교해 출력하면 된다.

C++의 경우, max 함수를 써서 최댓값을 구했다.

 

C++

#include <iostream>

using namespace std;
int main()
{
	int one, two, three;
	cin >>one>>two>>three;
	if(one==two&&two==three) // 셋 다 같으면
	{
		cout<<one*1000+10000;
	}
	else if(one==two||one==three) // 두개만 같다면
	{
		cout<<one*100+1000;
	}
	else if(two==three)
	{
		cout<<two*100+1000;
	}
	else
	{
		cout<<max(max(one,two),three)*100;
	}
}

Python

a,b,c=map(int,input().split())
if(a==b and b==c): print(a*1000+10000)
elif(a==b or a==c): print(a*100+1000)
elif(b==c): print(b*100+1000)
else: print(max(a,b,c)*100)

Java

import java.util.Scanner;

class Main 
{
  public static void main(String[] args)
  {
      Scanner sc=new Scanner(System.in);
      int a=sc.nextInt();
      int b=sc.nextInt();
      int c=sc.nextInt();
      int result;
      if(a==b&&b==c) result=a*1000+10000;
      else if(a==b||a==c) result=a*100+1000;
      else if(b==c) result=b*100+1000;
      else result=Math.max(Math.max(a,b),c)*100;
      System.out.println(result);
  }
}