'전체 글'에 해당되는 글 138건

  1. 2019.09.25 알람시계
  2. 2019.09.25 윤년
  3. 2019.09.25 시험 성적
  4. 2019.09.25 두 수 비교하기
  5. 2019.09.24 1차원 배열
  6. 2019.09.24 최대 공약수 구하기
  7. 2019.09.24 09.24 최대공약수 구하기
  8. 2019.09.23 09.23 Row와 Column 설정하기

알람시계

C#/Algorithm 2019. 9. 25. 16:15

문제

상근이는 매일 아침 알람을 듣고 일어난다. 알람을 듣고 바로 일어나면 다행이겠지만, 항상 조금만 더 자려는 마음 때문에 매일 학교를 지각하고 있다.

상근이는 모든 방법을 동원해보았지만, 조금만 더 자려는 마음은 그 어떤 것도 없앨 수가 없었다.

이런 상근이를 불쌍하게 보던, 창영이는 자신이 사용하는 방법을 추천해 주었다.

바로 "45분 일찍 알람 맞추기"이다.

이 방법은 단순하다. 원래 맞춰져있는 알람을 45분 앞서는 시간으로 바꾸는 것이다. 어차피 알람 소리를 들으면, 알람을 끄고 조금 더 잘 것이기 때문이다. 이 방법을 사용하면, 매일 아침 더 잤다는 기분을 느낄 수 있고, 학교도 지각하지 않게 된다.

현재 상근이가 맞춰논 알람 시각이 주어졌을 때, 창영이의 방법을 사용한다면, 이를 언제로 고쳐야 하는지 구하는 프로그램을 작성하시오.

입력

첫째 줄에 두 정수 H와 M이 주어진다. (0 ≤ H ≤ 23, 0 ≤ M ≤ 59) 그리고 이것은 현재 상근이가 맞춰놓은 알람 시간 H시 M분을 의미한다.

입력 시간은 24시간 표현을 사용한다. 24시간 표현에서 하루의 시작은 0:0(자정)이고, 끝은 23:59(다음날 자정 1분 전)이다. 시간을 나타낼 때, 불필요한 0은 사용하지 않는다.

출력

첫째 줄에 상근이가 창영이의 방법을 사용할 때, 맞춰야 하는 알람 시간을 출력한다. (입력과 같은 형태로 출력하면 된다.)

예제 입력 1

10 10

예제 출력 1

9 25

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _09._25_clock
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] arr = input.Split(' ');
            int H = Convert.ToInt32(arr[0]);
            int M = Convert.ToInt32(arr[1]);
            int minus = 45;
            bool HMrange = H >= 0 && H <= 23 && M >= 0 && M <= 59;
            if (HMrange)
            {
                if (M < minus && H > 0)
                {
                    H = H - 1;
                    M = 60 - (minus - M);
                    Console.WriteLine("{0} {1}", H, M);
                }
                else if (H < 1 && M < minus)
                {
                    H = 24 - 1;
                    M = 60 - (minus - M);
                    Console.WriteLine("{0} {1}", H, M);
 
                }
                else
                {
                    M = M - minus;
                    Console.WriteLine("{0} {1}", H, M);
 
                }
            }                               
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

'C# > Algorithm' 카테고리의 다른 글

설탕 배달  (0) 2019.09.25
세 수  (0) 2019.09.25
윤년  (0) 2019.09.25
시험 성적  (0) 2019.09.25
두 수 비교하기  (0) 2019.09.25
:

윤년

C#/Algorithm 2019. 9. 25. 16:14

문제

연도가 주어졌을 때, 윤년이면 1, 아니면 0을 출력하는 프로그램을 작성하시오.

윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때 이다.

예를들어, 2012년은 4의 배수라서 윤년이지만, 1900년은 4의 배수이지만, 100의 배수이기 때문에 윤년이 아니다.

하지만, 2000년은 400의 배수이기 때문에 윤년이다.

입력

첫째 줄에 연도가 주어진다. 연도는 1보다 크거나 같고, 4000보다 작거나 같은 자연수이다.

출력

첫째 줄에 윤년이면 1, 아니면 0을 출력한다.

예제 입력 1

2000

예제 출력 1

1

코드 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _09_24_step3
{
    class Program
    {
        static void Main(string[] args)
        {
                int year = int.Parse(Console.ReadLine());
                if (year % 4 == 0)
                {
                    if (year % 100 != 0 || year % 400 == 0)
                    {
                        Console.WriteLine(1);
                    }
                    else
                    {
                        Console.WriteLine(0);
                    }
                }
                else 
                {
                    Console.WriteLine(0);
                }            
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

'C# > Algorithm' 카테고리의 다른 글

설탕 배달  (0) 2019.09.25
세 수  (0) 2019.09.25
알람시계  (0) 2019.09.25
시험 성적  (0) 2019.09.25
두 수 비교하기  (0) 2019.09.25
:

시험 성적

C#/Algorithm 2019. 9. 25. 16:13

문제

시험 점수를 입력받아 90 ~ 100점은 A, 80 ~ 89점은 B, 70 ~ 79점은 C, 60 ~ 69점은 D, 나머지 점수는 F를 출력하는 프로그램을 작성하시오.

입력

첫째 줄에 시험 점수가 주어진다. 시험 점수는 0보다 크거나 같고, 100보다 작거나 같은 정수이다.

출력

시험 성적을 출력한다.

예제 입력 1

100

예제 출력 1

A

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _9498
{
    class Program
    {
        static void Main(string[] args)
        {
            int score = Convert.ToInt32(Console.ReadLine());
            if (score>=90 && score<=100)
            {
                Console.WriteLine("A");
            }
            else if (score >= 80 && score <= 89)
            {
                Console.WriteLine("B");
            }
            else if (score >= 70 && score <= 79)
            {
                Console.WriteLine("C");
            }
            else if (score >= 60 && score <= 69)
            {
                Console.WriteLine("D");
            }
            else
            {
                Console.WriteLine("F");
            }
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

참조:https://www.acmicpc.net/source/15322059

'C# > Algorithm' 카테고리의 다른 글

설탕 배달  (0) 2019.09.25
세 수  (0) 2019.09.25
알람시계  (0) 2019.09.25
윤년  (0) 2019.09.25
두 수 비교하기  (0) 2019.09.25
:

두 수 비교하기

C#/Algorithm 2019. 9. 25. 16:10

문제

두 정수 A와 B가 주어졌을 때, A와 B를 비교하는 프로그램을 작성하시오.

입력

첫째 줄에 A와 B가 주어진다. A와 B는 공백 한 칸으로 구분되어져 있다.

출력

첫째 줄에 다음 세 가지 중 하나를 출력한다.

  • A가 B보다 큰 경우에는 '>'를 출력한다.
  • A가 B보다 작은 경우에는 '<'를 출력한다.
  • A와 B가 같은 경우에는 '=='를 출력한다.

제한

  • -10,000 ≤ A, B ≤ 10,000

예제 입력 1

1 2

예제 출력 1

<

예제 입력 2

10 2

예제 출력 2

>

예제 입력 3

5 5

예제 출력 3

==

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _1330
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] array = input.Split(' ');
            int a = Convert.ToInt32(array[0]);
            int b = Convert.ToInt32(array[1]);
            if (a> b)
            {
                Console.WriteLine(">");
            }
            else if (a<b)
            {
                Console.WriteLine("<");
            }
            else
            {
                Console.WriteLine("==");
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

참조:https://www.acmicpc.net/problem/1330

'C# > Algorithm' 카테고리의 다른 글

설탕 배달  (0) 2019.09.25
세 수  (0) 2019.09.25
알람시계  (0) 2019.09.25
윤년  (0) 2019.09.25
시험 성적  (0) 2019.09.25
:

1차원 배열

C#/Study 2019. 9. 24. 17:41

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Sample input"); //콘솔 창에 Sample input 출력
            String number = Console.ReadLine(); // 사용자의 입력을 String형 number에 저장
            int number2 = Convert.ToInt32(number); //String형 number를 int32로 변환하여 number2에 저장
            int[] array = new int[number2]; // int형 배열 크기가 number2인 배열 array 생성
            Console.WriteLine(number2); // number2값 콘솔 창에 출력
            for (int i = 0; i < number2; i++)
            {
                String value = Console.ReadLine();
                int value2 = Convert.ToInt32(value);
                array[i] = value2;
            }
            for (int i = 0; i < number2; i++)
            {
                Console.WriteLine(array[i]);
            }
            Console.ReadLine();
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

출력:

 

'C# > Study' 카테고리의 다른 글

박싱과 언박싱  (0) 2019.10.31
배열 내 요소중 최대값 구하기  (0) 2019.10.15
성적표만들기  (0) 2019.09.27
09.23 Row와 Column 설정하기  (0) 2019.09.23
문자열 표현방식  (0) 2019.09.19
:

최대 공약수 구하기

C#/Problems 2019. 9. 24. 17:34

공약수는 

            int num1 = int.Parse(Console.ReadLine());
            int num2 = int.Parse(Console.ReadLine());            
            for (int i = 1; i < num1 || i<num2; i++)
            {
                if (num1 % i == 0 && num2 % i == 0) //공약수
                {
                    Console.WriteLine(i);
                }                         
            }
코드를 통해 구할수 있었지만 최대 공약수를 구하려면 공약수 끼리 비교를 해야한다는 생각때문에 난관에 부딪혔었다.

정답 코드:

int num1 = int.Parse(Console.ReadLine());
            int num2 = int.Parse(Console.ReadLine());
            int sum = 0;
            for (int i = 1; i < num1 || i<num2; i++)
            {
                if (num1 % i == 0 && num2 % i == 0) //공약수
                {
                    sum = i;
                }                         
            }
            Console.WriteLine(sum);
            

하지만 새로운 변수 sum을 만들어 공약수가 높아지면서 이를 갱신 할수있었고, 더이상 갱신 할 값이 없을때 포문이 종료되는것을 이용해 포문 밖에 출력 메세지를 써서 최대공략수만 쓸수 있게 되었다.

:

09.24 최대공약수 구하기

C#/실습 2019. 9. 24. 17:29

예제:

두수의 최대공약수구하기

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
 
namespace _09_24_step4
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1 = int.Parse(Console.ReadLine());
            int num2 = int.Parse(Console.ReadLine());
            int sum = 0;
            for (int i = 1; i < num1 || i<num2; i++)
            {
                if (num1 % i == 0 && num2 % i == 0) //공약수
                {
                    sum = i;
                }                         
            }
            Console.WriteLine(sum);
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

'C# > 실습' 카테고리의 다른 글

워크래프트 캐릭생성하기  (0) 2019.09.27
switch 문  (0) 2019.09.26
09.23 상점 구매하기 및 판매하기  (0) 2019.09.23
09.20 줄넘기  (0) 2019.09.20
09.20 for문을 이용한 던전게임  (0) 2019.09.20
:

09.23 Row와 Column 설정하기

C#/Study 2019. 9. 23. 17:21

예제:

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax07
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Row값을 입력하세요: ");
            string strX = Console.ReadLine();
            int x = Convert.ToInt32(strX);
            Console.Write("Col값을 입력하세요: ");
            string strY = Console.ReadLine();
            int y = Convert.ToInt32(strY);
            for (int c = 0; c<x; c++)
            {
                for (int i =0; i<y; i++)
                {
                    Console.Write($"({i},{c})\t");
                }
                Console.WriteLine();
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

'C# > Study' 카테고리의 다른 글

박싱과 언박싱  (0) 2019.10.31
배열 내 요소중 최대값 구하기  (0) 2019.10.15
성적표만들기  (0) 2019.09.27
1차원 배열  (0) 2019.09.24
문자열 표현방식  (0) 2019.09.19
: