작성일 :

문제 링크

30676번 - 이 별은 무슨 색일까

설명

별빛의 파장이 주어질 때, 파장 구간에 따라 색상을 판별하여 출력하는 문제입니다.


접근법

파장 값에 따라 조건 분기로 해당하는 색상 문자열을 출력합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;

class Program {
  static void Main() {
    var lambda = int.Parse(Console.ReadLine()!);
    var color = "";
    if (lambda >= 620) color = "Red";
    else if (lambda >= 590) color = "Orange";
    else if (lambda >= 570) color = "Yellow";
    else if (lambda >= 495) color = "Green";
    else if (lambda >= 450) color = "Blue";
    else if (lambda >= 425) color = "Indigo";
    else color = "Violet";
    Console.WriteLine(color);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int lambda; cin >> lambda;

  string color;
  if (lambda >= 620) color = "Red";
  else if (lambda >= 590) color = "Orange";
  else if (lambda >= 570) color = "Yellow";
  else if (lambda >= 495) color = "Green";
  else if (lambda >= 450) color = "Blue";
  else if (lambda >= 425) color = "Indigo";
  else color = "Violet";

  cout << color << "\n";

  return 0;
}