boj 문제풀이

HIROYOSHI·2022년 1월 26일
1

boj

목록 보기
1/2

백준 1271번

import java.math.BigInteger;

import java.util.*;

public class Main{

 public static void main(String args[]) {

      Scanner in = new Scanner(System.in);

      BigInteger i = in.nextBigInteger();

      BigInteger j = in.nextBigInteger();

      BigInteger res = new BigInteger("0");

      BigInteger res2 = new BigInteger("0");

      res = i.divide(j);

      res2 = i.mod(j);

      System.out.println(res + "\n" + res2);

      in.close();

 }

}

배운거: 너무 큰 변수를 받을 때는 BigInteger 를 사용한다.

math파일에 divide메소드 사용하여 나눌 수 있고, mod메소드를 사용하여 나머지를 구할 수 있다.

 백준 1550번

import java.util.*;

public class Main{

 public static void main(String args[]) {

      Scanner in = new Scanner(System.in);

      String s = in.next();

      System.out.println(Integer.parseInt(s,16));

      in.close();

  }

}

배운점: 진수변환을 하기위해서는 일단 String 으로 받고 Integer.parseInt를 사용하여 s라는 String타입 변수를

16진수에서 10진수로 변환을 한다.!

 백준 2338번

import java.math.BigInteger;

import java.util.*;

 public class Main{

 public static void main(String args[]){

      Scanner in = new Scanner(System.in);

      BigInteger m = in.nextBigInteger();

      BigInteger n = in.nextBigInteger();

      System.out.println(m.add(n));

      System.out.println(m.subtract(n));

      System.out.println(m.multiply(n));

 }

}

배운점: 계산은 무조건 BigInteger를 사용하라,,, 더하기는 add 빼기는 subtract 곱하기는 multiply

이제 이런 비슷한 문제 나오면 바로 풀 수 있을듯

 백준 2558번

import java.util.Scanner;

import java.math.BigInteger;

public class Main{

 public static void main(String args[]){

      Scanner in = new Scanner(System.in);

      BigInteger a = in.nextBigInteger();

      BigInteger b = in.nextBigInteger();

      System.out.println(a.add(b));

 }

}

이번에는 코드를 하나도 참고 안하고 기본 틀도 복붙안하고 한번에 오류없이 통과했다.

 백준 2845번

import java.util.Scanner;

import java.math.BigInteger;

public class Main{

public static void main(String args[]){

 Scanner in = new Scanner(System.in);

 BigInteger l = in.nextBigInteger();

 BigInteger w = in.nextBigInteger();

 BigInteger area = l.multiply(w);

 for(int i=0; i<5; i++){

      BigInteger areas = in.nextBigInteger();

      System.out.print(areas.subtract(area)+" ");

      }

 }

}
day 5/22

profile
KNU COMPUTER ENGINEERING

0개의 댓글