728x90

프로그램 명:leap_year

자연수를 입력으로 받아 윤년이면 YES , 아니면 NO 를 출력하는 프로그램을 작성하시오.

 

윤년이란 ,

 

4의 배수이고 100 의 배수가 아님.

400 의 배수임

두 가지중 하나라도 참이면 윤년

 

입력

입력되는 수는 3000 이하의 자연수이다.

 

입출력 예

입력

4

 

출력

YES

 

입력 

100

 

출력

NO

 

입력

200

 

출력 

NO

 

입력 

400

 

출력

YES 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
 
namespace Quiz_LeapYear
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
 
            if (((n % 4 == 0&& (n % 100 != 0)) || (n % 400 == 0))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}
cs

 

프로그램 명: gcd_lcm 

두 수의 최대 공약수와 최소 공배수를 출력하는 프로그램을 작성하시오.

입력

1000 이하의 자연수를 입력으로 받는다.

출력

한 줄에 두 수를 출력한다. 첫번째 수는 최대 공약수이고 , 다음 수는 최소 공배수이다.

입출력 예

입력

 

4 6

 

출력

 

2 12

 

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
44
45
46
47
using System;
 
namespace Quiz_GcdLcm
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] splitmp = Console.ReadLine().Split(' ');
            int bign = int.Parse(splitmp[0]);
            int smalln = int.Parse(splitmp[1]);
            int yaksu = 0;
            int baesu = 0;
            if (bign < smalln)
            {
                int temp = bign;
                bign = smalln;
                smalln = temp;
            }
 
            for(int i = 1; i < smalln; i++)
            {
                if (smalln % i == 0)
                {
                    if (bign % i == 0)
                    {
                        yaksu = i;
                    }
                }
            }
 
            for(int i=bign; ; i++)
            {
                if (i % bign == 0)
                {
                    if (i % smalln == 0)
                    {
                        baesu = i;
                        break;
                    }
                }
            }
 
            Console.Write(yaksu + " " + baesu);
        }
    }
}
cs

 

유클리드 호제법 공식

 

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
44
45
using System;
 
namespace GCD_001
{
    class Program
    {
        static int gcd(int a, int b)
        {
            int temp, n;
            if (a < b)
            {
                temp = a;
                a = b;
                b = temp;
            }
 
 
            // 유클리드 호제법
            // 값 = a(제수) % b(피제수)
            // a = b
            // b = 값
            // 나머지가 없을 때까지 반복
            while (b != 0)
            {
                n = a % b;
                a = b;
                b = n;
            }
            return a;
        }
        static int lcm(int x, int y)
        {
            return (x * y) / gcd(x, y); // 최대공약수
        }
        static void Main(string[] args)
        {
            int result_gcd, result_lcm;
            result_gcd = gcd(100200);
            result_lcm = lcm(46);
 
            Console.WriteLine(result_gcd);
            Console.WriteLine(result_lcm);
        }
    }
}
cs

 

프로그램 명: interest 

농부 존은 소를 키워 많은 돈을 벌었다. 이 돈을 은행에 예치한 후 몇 년후에 이 원금이 얼마가 될지가 궁금하다.

연이자 R ( 0 .. 20 사이) ,

원금 M ( 100 .. 1,000,000) ,

유치할 년수 Y ( 0..400) 가

입력으로 주어질 때 최종 금액을 출력하시오.(원금이 계속 불어나는 복리법으로)

마지막 최종금액이 소수점을 포함한다면 소수점을 버리고 , 답은 2^31 -1 보다는 크지 않다.

 

입력

R,M,Y 가 입력된다.

출력

Y 년 후의 최종 금액을 출력한다.

입출력 예

입력

5 5000 4

 

출력

6077

 

권장 사항

소수를 포함한 연산에서 정확한 값을 내기 위해서 float 보다 double 로

 

힌트

 

복리법이란?

 

 

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;
 
namespace Quiz_Interest
{
    class Program
    {
        public static double interest(int r, int m, int y)
        {
            if (y == 1)
            {
                return m * ((double)(100 + r) / 100);
            }
            return ((double)(100 + r) / 100* interest(r, m, y - 1);
        }
        static void Main(string[] args)
        {
            string[] splitmp = Console.ReadLine().Split();
            int R = int.Parse(splitmp[0]);
            int M = int.Parse(splitmp[1]);
            int Y = int.Parse(splitmp[2]);
            int result = 0;
 
            result = (int)interest(R, M, Y);
            Console.WriteLine(result);
        }
    }
}
cs

 

1. virtual box 설치 64bit ver 6.x

2. ubuntu 18.04 lts version

 

[VirtualBox] Ubuntu 18.04 설치 순서

 

OS설치 후 프로그램 설정 방법

 

1. sudo apt update 

   업데이트 받을 주소를 갱신한다.

 

2. sudo apt install vim

   우분투에 처음 설치되어있는 vi 에디터는 Lite 버전이다. Full버전으로 교체한다.

 

3. sudo vi /etc/apt/sources.list

   명령어모드에서 :%s/kr.archive.ubuntu.com/ftp.daumkakao.com

   저장은 :wq  (w 쓰기 q 종료)

   콘솔 상에서 $>sudo apt update  (업데이트 사이트 주소 갱신)

   ftp.daumkakao.com 다운로드가 빠른 미러사이트로 교체

 

4. sudo install gcc make net-tools

   gcc - c 컴파일러

   make - 빌드순서 정리

   net-tools - 네트워크관련 유틸리티

 

5. 호스트키 변경법 -> Ctrl + ALT + Shift로 변경하자

   버추얼박스 메뉴 --> 환경설정 --> 입력 --> 가상머신 --> 호스트키 조합 

 

6. 게스트 확장 이미지 설치

   VM화면에서 장치 --> 게스트 확장 이미지 삽입

   Ubuntu18.04 부터는 gcc와 make가 설치 되어있지 않아서 4번 단계에서 설치 해주어야 동작

   CD이미지 실행 후 리부팅(sudo reboot)

 

7. 네트워크 동작방식 NAT에서 브리지 방식으로 변경

   VirtualBox 메뉴 중 네트워크 --> 어댑터1 --> 어댑터에 브리지

   재부팅 후 IP를 확인하면 윈도우와 같은 망내에 존재

 

8. openssh-server 설치 후 테스트

   $>sudo apt install openssh-server

 

   클라이언트 프로그램 : putty 또는 XShell

 

9. 웹서버 설치

  $> sudo apt install apache2 

 

옵션1. Django 설치

  $> sudo apt install python3-pip

  $> pip3 install Django

  $> sudo apt install python-django-common

  $> sudo apt install python3-django

 

  설치 확인법

  $> python3

 >>> import django

 >>> print(django.get_version())

 

728x90
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기