C++ 출력만 해보고 앞으로 C#으로 해보겠습니다. 유니티로 취업을 할거고 계속 사용해서 친해져야하는 언어이므로 앞으로 문제는 C#으로 풀어보겠습니다.
두 수 비교하기
using System;
class Program {
static void Main(){
string str;
int a,b;
str = Console.ReadLine();
string[] strArr = str.Split(' ');
a = Convert.ToInt32(strArr[0]);
b = Convert.ToInt32(strArr[1]);
if(a < b)
Console.WriteLine("<");
else if(a > b)
Console.WriteLine(">");
else if(a == b)
Console.WriteLine("==");
else
Console.WriteLine("잘못된 입력 값입니다.");
}
}
시험 성적
string str;
int score;
str = Console.ReadLine();
score = Convert.ToInt32(str);
if(score >= 90)
Console.WriteLine("A");
else if(score >= 80)
Console.WriteLine("B");
else if(score >= 70)
Console.WriteLine("C");
else if(score >= 60)
Console.WriteLine("D");
else
Console.WriteLine("F");
윤년
string str;
int year;
int a = 4;
int b = 100;
int c = 400;
bool yearBool;
str = Console.ReadLine();
year = Convert.ToInt32(str);
yearBool = year%a == 0 && year%b != 0;
if(yearBool || year%c == 0)
Console.WriteLine("1");
else
Console.WriteLine("0");
사분면 고르기
int a,b;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
if (a > 0 && b > 0)
Console.WriteLine("1");
else if(a < 0 && b > 0)
Console.WriteLine("2");
else if(a < 0 && b < 0)
Console.WriteLine("3");
else if(a > 0 && b < 0)
Console.WriteLine("4");
else
Console.WriteLine("잘못 입력했습니다.");
Convert.ToInt32 보다 int.Parse 속도, 메모리 면에서 더 유리합니다.
알람 시계
int h,m;
int setM;
string[] arrStr = Console.ReadLine().Split(" ");
setM = 45;
h = int.Parse(arrStr[0]);
m = int.Parse(arrStr[1]);
m -= setM;
if (m < 0) {
m = Math.Abs(m);
m = 60 - m;
h -= 1;
}
if(h < 0)
{
h = 23;
}
Console.WriteLine("{0} {1}", h,m);
if문 완료했습니다.
'프로그래밍 공부 > 알고리즘' 카테고리의 다른 글
C++ 백준 while문 (0) | 2021.06.10 |
---|---|
Day1 백준 입출력과 사칙연산 (0) | 2021.05.25 |
[알고리즘] C# ArrayList와 LinkedList (0) | 2021.05.15 |
[알고리즘] C# 배열 재정리 (0) | 2021.05.15 |
[알고리즘] 자료구조? (0) | 2021.05.15 |