'전체 글'에 해당하는 글 45건

문제 요약

1, 2, 3, 4, 5...의 데이터가 담겨있는 int형 배열 q[]

뒤의 숫자는 앞으로 최대 두 칸까지 이동할 수 있다.

 

세 칸 이상 이동 시 : Too chaotic 출력

그 외 : 앞으로 이동한 횟수를 출력

 

 

Too chaotic 출력

각 숫자 i는 i - 1 인덱스에 위치한다.

   숫자 4는, 현재 3인덱스에 위치 ( q[3] = 4)

   숫자 4는 최대 두 칸 앞으로 이동할 수 있으므로

   인덱스 2, 1에 위치할 수 있다. ( q[2] = 4, q[1] = 4 가능)

   인덱스 0에 위치 시 Too chaotic( q[0] = 4인 경우 Too chaotic)

즉 q[i] - 1 - i > 2 일 때 Too chaotic이 출력되도록 한다.

 

 

birbe출력

q[j] > q[i] (j < i) 인 이유

처음 배열 q의 값들은 오름차순으로 정렬되어있어 앞의 값이 뒤의 값보다 작다.

하지만 배열 q의 값들이 앞으로 이동했을 경우 앞의 값이 뒤의 값보다 큰 경우가 발생

따라서 q[0] ~ q[i - 1] 중에서 q[i]의 값보다 큰 값의 개수를 세어 보면 이동한 숫자를 알 수 있다.

 

ex) 현재 q[] = {1, 2, 3, 4, 5}

숫자 4가 앞으로 한 칸 이동 

q[] = {1, 2, 4, 3, 5}

= 숫자 1 앞에 1보다 큰 값 없음

  숫자 2 앞에 2보다 큰 값 없음

  숫자 4 앞에 4보다 큰 값 없음

  숫자 3 앞에 3보다 큰 값은 4 하나

  숫자 5 앞에 5보다 큰 값 없음

= 총 한 번 이동

 

숫자 4가 앞으로 두 칸 이동

q[] = {1, 4, 2, 3, 5}

= 숫자 1 앞에 1보다 큰 값 없음

  숫자 4 앞에 4보다 큰 값 없음

  숫자 2 앞에 2보다 큰 값 4 하나

  숫자 3 앞에 3보다 큰 값은 4 하나

  숫자 5 앞에 5보다 큰 값 없음

= 총 두 번 이동

 

 

Max(0, q[i] - 2)의 이유

앞의 값과 비교할 때 q[0] ~ q[i - 1]까지 계속 비교할 필요가 없음

최대 앞으로 두칸 이동할 수 있기 때문에

q[i] - 2 부터 비교하면 됨

 

ex)

q[i]가 4일 때 4보다 큰 값은 5, 6, 7...이 있음

5는 최대 q[2]까지만, 6은 q[3]까지만 이동 가능

즉, q[2]이부터 q[i - 1]까지 4보다 큰 값의 개수를 찾으면 됨

 

 

 

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

Array Manipulation c#  (0) 2020.05.03
Hash Tables: Ransom Note c#  (0) 2020.04.15
Arrays: Left Rotation C#  (0) 2020.03.27
Jumping on the Clouds C#  (0) 2020.03.21
Repeated String C#  (0) 2020.03.21

WRITTEN BY
beautifulhill

,

composer 설치가 지원되지 않는 버전에서 사용

 

1. wkhtmltopdf 다운로드 - OS에 맞게 다운로드를 한다.

 

https://wkhtmltopdf.org/downloads.html

 

wkhtmltopdf

All downloads are currently hosted via Github releases, so you can browse for a specific download or use the links below. Stable The current stable series is 0.12.5, which was released on June 11, 2018 – see changes since 0.12.4. OS Flavor Downloads Commen

wkhtmltopdf.org

 

 

 

2. .rpm 파일의 압축을 풀어준다.

- 7-Zip 을 추천

 

 

3. wkhtmltox-0.12.5-1.centos6.x86_64.cpio 압축을 풀어준다.

 

 

4. usr/local 폴더에 bin, include, lib, share 폴더가 나온다.

 

이 폴더 안의 파일들을 각 위치에 맞게 실서버에 올린다

 

 

5. 코드 작성

 

index.php

<form name="WkhtmlPdfForm" id="WkhtmlPdfForm" action="/pdf_down.php" method="post" accept-charset="UTF-8" enctype="multipart/form-data">
	파라미터들
</form>

pdf_down.php

<?

header('Content-Type: text/html; charset=UTF-8');
$url = "http://www.naver.com";
$down_name = "test";

//tmp폴더의 test.pdf 저장
exec('/usr/local/bin/wkhtmltopdf -L 10mm -R 10mm -T 10mm -B 10mm "'.$url.'" "tmp/'.$down_name.'.pdf" 2>&1');

//tmp폴더의 test.pdf를 클라이언트가 다운받을 수 있도록
$sFilePath = 'tmp/'.$down_name.'.pdf';
$sFileName = $down_name.'.pdf';

header("Content-Disposition: attachment; filename=\"".$sFileName."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strval(filesize($sFilePath)));
header("Cache-Control: cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");

echo file_get_contents($sFilePath);
flush();
unlink($sFilePath);//tmp폴더의 test.pdf 파일을 삭제

?>

 

 

6. wkhtmltopdf font 적용 안될 때

usr/share/fonts/원하는 폰트.ttf 을 업로드한다.(폰트 설치)

 

 

 


WRITTEN BY
beautifulhill

,

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

Hash Tables: Ransom Note c#  (0) 2020.04.15
New Year Chaos c#  (1) 2020.04.05
Jumping on the Clouds C#  (0) 2020.03.21
Repeated String C#  (0) 2020.03.21
Counting Valleys c#  (0) 2020.03.21

WRITTEN BY
beautifulhill

,

추상클래스

프로그래밍/C# 2020. 3. 22. 16:47

추상 클래스, 추상 메서드

   virtual 예약어로는 자식클래스가 반드시 재정의(override)를 하도록 강제 할 수 없음

   추상메서드를 통해 자식들이 반드시 재정의 하도록 강요 

   부모 클래스에서 abstract 예약어를 지정

   자식 클래스에서 override 예약어를 사용하여 재정의

   구현코드가 없음

   추상클래스는 new를 사용해 인스턴스를 만들 수 없음

   추상메서드는 추상클래스 안에서만 선언

   다중상속 불가능

 

using System;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            //Food food = new Food();/*오류: 추상클래스 new 사용 불가능*/
            Food coke = new Coke();
            coke.Eat(); //마신다
            Console.WriteLine(coke.Sell(1000));// 1000원을 낸다.
        }
    }
    abstract class Food
    {
        public abstract string Sell(int won);
        virtual public void Eat()
        {
            Console.WriteLine("먹는다");
        }
    }    
    class Coke : Food
    {
        public override string Sell(int won)
        {
            return won + "원을 낸다.";
        }
        new public void Eat()
        {
            Console.WriteLine("마신다");
        }
    }
}

 

'프로그래밍 > C#' 카테고리의 다른 글

다형성  (0) 2020.03.22
Object 의 메서드 - ToString, GetType, Equals, GetHashCode  (0) 2020.03.22
as, is 연산자  (0) 2020.03.20
객체지향 - 3  (0) 2020.03.20
객체지향 -2  (0) 2020.03.20

WRITTEN BY
beautifulhill

,

다형성

프로그래밍/C# 2020. 3. 22. 16:11

다형성 

   하나의 클래스나 메서드가 다양한 방식으로 동작하는 것

   override

   overrode

 

 

override

   부모 클래스의 메소드에는 virtual 예약어를 통해 가상 메서드 생성

   자식 클래스의 메소드에는 override를 통해 다형성 구현

   new 예약어는 override를 사용해 재정의한 것이 아니라 독립적인 메서드이므로 

       자식 클래스를 부모클래스로 암시적 형변환시 부모클래스의 메서드가 불러와진다.

   base 예약어는 부모클래스의 메서드를 호출함

   base 예약어는 부모클래스와 자식클래스 간 중복 된 코드가 있을 경우에 사용

using System;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Food food = new Food();
            food.Eat(); //먹는다
            Food bibim = new Bibim();
            bibim.Eat(); //비빈다
            Food coke = new Coke();
            coke.Eat(); //먹는다
            Food bbq = new Bbq();
            bbq.Eat();//굽는다 먹는다
        }
    }
    class Food
    {
        virtual public void Eat() { 
            Console.WriteLine("먹는다"); 
        }
    }
    class Bibim : Food
    {
        override public void Eat()
        {
            Console.WriteLine("비빈다");
        }
    }
    class Coke : Food
    {
        new public void Eat()
        {
            Console.WriteLine("마신다");
        }
    }
    class Bbq : Food
    {
        override public void Eat()
        {
            Console.WriteLine("굽는다");
            base.Eat();
        }
    }

}

 

Object 기본메서드 확장 - ToString 확장

   ovveride(재정의) 안했을 때

using System;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Food food = new Food();
            Console.WriteLine(food.ToString());
        }
    }
    class Food
    {
    }
}

   ovveride(재정의) 했을 때

using System;

namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Food food = new Food();
            Console.WriteLine(food.ToString());
        }
    }
    class Food
    {
        public override string ToString()
        {
            return  "먹는다.";
        }
    }
}

 

 

overrode

   메서드의 이름만 같음

   매개변수의 수, 개별 매개변수 타입, 반환값 등은 다를 수 있음

   ex) 다중생성자

'프로그래밍 > C#' 카테고리의 다른 글

추상클래스  (0) 2020.03.22
Object 의 메서드 - ToString, GetType, Equals, GetHashCode  (0) 2020.03.22
as, is 연산자  (0) 2020.03.20
객체지향 - 3  (0) 2020.03.20
객체지향 -2  (0) 2020.03.20

WRITTEN BY
beautifulhill

,

System.Object

   System이라는 네임스페이스의 Object라는 클래스

   모든 타입의 조상

   기본적으로 object에서 상속받는 가정하에 코드를 생성한다.

 

Object의 메서드 - ToString

   해당 인스턴스가 속한 클래스의 전체 이름 FQDN을 반환

   기본타입의 경우 클래스의 전체 이름이 아닌 값을 반환

   하위클래스에서 재정의 가능

using System;
namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Parent p = new Parent();
            string s = "sample";
            int n = 0;
            Console.WriteLine(p.ToString());
            Console.WriteLine(s.ToString());
            Console.WriteLine(n.ToString());
        }
    }
    class Parent{ }
    class Children : Parent {
        public void Method1()
        {
        }
    }
}

 

Object의 메서드 - GetType

  상속 Object -> MemberInfo -> Type 이므로 class 로 타입을 정의할 경우 System.Type 인스턴스를 보유한다.

   GetType은 타입 전체 이름을 반환

   FullName, IsClass, IsArray 프로퍼티를 가지고 있음

using System;
namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Parent p = new Parent();
            string s = "sample";
            int n = 0;
            Console.WriteLine(p.GetType());
            Console.WriteLine(s.GetType());
            Console.WriteLine(n.GetType());
        }
    }
    class Parent{ }
    class Children : Parent {
        public void Method1()
        {
        }
    }
}

 

Object의 메서드 - Equals

   stack에 할당된 값(참조형식의 경우 힙메모리 위치)를 비교

   값형식 : 값을 대상으로 비교

   참조형식 : 할당된 메모리의 위치를 가리키는 식별자의 값 비교

using System;
namespace Example
{
    class Program
    {
        static void Main(string [] args)
        {
            Parent p = new Parent();
            Parent p1 = new Parent();
            string s = "sample";
            string s1 = "sample";
            int n = 0;
            int n1 = 0;
            Console.WriteLine(p.Equals(p1));
            Console.WriteLine(s.Equals(s1));
            Console.WriteLine(n.Equals(n1));
        }
    }
    class Parent{ }
    class Children : Parent {
        public void Method1()
        {
        }
    }
}

 

 

Object의 메서드 - GetHashCode

   인스턴스를 식별할 수 있는 4바이트의 int값을 반환

   타입이 int인 경우는 값을 반환

   long 타입의 경우 8바이트이기 때문에 값이 다름에도 동일한 해시코드가 반환될 수 있음

   해시 충돌이 발생할 수 있으므로 Equals 와 같이 사용

   GetHashCode 의 반환값이 같으면 Equals로 재확인

 

'프로그래밍 > C#' 카테고리의 다른 글

추상클래스  (0) 2020.03.22
다형성  (0) 2020.03.22
as, is 연산자  (0) 2020.03.20
객체지향 - 3  (0) 2020.03.20
객체지향 -2  (0) 2020.03.20

WRITTEN BY
beautifulhill

,

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

New Year Chaos c#  (1) 2020.04.05
Arrays: Left Rotation C#  (0) 2020.03.27
Repeated String C#  (0) 2020.03.21
Counting Valleys c#  (0) 2020.03.21
Sock Merchant C#  (0) 2020.03.20

WRITTEN BY
beautifulhill

,

Repeated String C#

알고리즘/C# 2020. 3. 21. 22:45

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

New Year Chaos c#  (1) 2020.04.05
Arrays: Left Rotation C#  (0) 2020.03.27
Jumping on the Clouds C#  (0) 2020.03.21
Counting Valleys c#  (0) 2020.03.21
Sock Merchant C#  (0) 2020.03.20

WRITTEN BY
beautifulhill

,