[코드업 기초 100제] [기초 - 종합] 코드업 1078 ~ 1092 자바 풀이

2022. 2. 16. 00:18코딩테스트/코드업

728x90
반응형

문제 출처


https://github.com/haessae0/MCTP

 

1078. 짝수 합 구하기

import java.io.*;

public class codeup1078 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int data = Integer.parseInt(br.readLine());

    int cnt = 0;

    for (int i = 0; i <= data; i++) {
      if (i % 2 == 0) {
        cnt += i;
      }
    }
    System.out.print(cnt);
  }

}

 

1079. 원하는 문자가 입력될 때까지 반복 출력하기

import java.util.Scanner;

public class codeup1079 {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);

    while (true) {
      char a = sc.next().charAt(0);
      if (a != 'q') {
        System.out.println(a);
      } else {
        System.out.println(a);
        break;
      }
    }

  }

}

 

1080. 언제까지 더해야 할까?

import java.util.Scanner;

public class codeup1080 {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int data = sc.nextInt();
    int cnt = 0;
    for (int i = 1; i <= data; i++) {
      cnt += i;
      if (cnt >= data) {
        System.out.print(i);
        break;
      }
    }

  }

}

 

1081. 주사위를 2개 던지면?

import java.io.*;

public class codeup1081 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String array[] = br.readLine().split(" ");
    int a = Integer.parseInt(array[0]);
    int b = Integer.parseInt(array[1]);

    for (int i = 1; i <= a; i++) {
      for (int j = 1; j <= b; j++) {
        System.out.println(String.format("%d %d", i, j));
      }
    }
  }

}

 

1082. 16진수 구구단?

import java.io.*;

public class codeup1082 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String a = br.readLine();

    int data = Integer.parseInt(a, 16);

    for (int i = 1; i < 16; i++) {
      System.out.println(String.format("%X*%X=%X", data, i, data * i));
    }
  }

}

 

1083. 3 6 9 게임의 왕이 되자!

import java.io.*;

public class codeup1083 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int a = Integer.parseInt(br.readLine());

    for (int i = 1; i <= a; i++) {
      if (i == 3 || i == 6 || i == 9) {
        System.out.print("X ");
      } else {
        System.out.print(i + " ");
      }
    }
  }

}

 

1084. 빛 섞어 색 만들기

import java.io.*;

public class codeup1084 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    String array[] = br.readLine().split(" ");

    int r = Integer.valueOf(array[0]);
    int g = Integer.valueOf(array[1]);
    int b = Integer.valueOf(array[2]);

    int cnt = 0;

    for (int i = 0; i < r; i++) {
      for (int j = 0; j < g; j++) {
        for (int k = 0; k < b; k++) {
          bw.write(i + " " + j + " " + k + "\n");
          cnt++;
        }
      }
    }

    bw.write(String.valueOf(cnt));
    bw.flush();
  }

}

 

1085. 소리 파일을 저장용량 계산하기

import java.io.*;

public class codeup1085 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String array[] = br.readLine().split(" ");

    long h = Long.parseLong(array[0]);
    long b = Long.parseLong(array[1]);
    long c = Long.parseLong(array[2]);
    long s = Long.parseLong(array[3]);

    double data = (((h * b * c * s) / 8) / Math.pow(2, 10)) / Math.pow(2, 10);

    System.out.printf("%.1f MB", data);
  }

}

 

1086. 그림 파일 저장용량 계산하기

import java.io.*;

public class codeup1086 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String array[] = br.readLine().split(" ");

    long h = Long.parseLong(array[0]);
    long b = Long.parseLong(array[1]);
    long c = Long.parseLong(array[2]);

    double data = (((h * b * c) / 8) / Math.pow(2, 10)) / Math.pow(2, 10);

    System.out.printf("%.2f MB", data);
  }

}

 

1087. 여기까지! 이제 그만~

import java.io.*;

public class codeup1087 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int a = Integer.parseInt(br.readLine());

    int cnt = 0;

    for (int i = 1; i <= a; i++) {
      cnt += i;
      if (cnt >= a) {

        break;
      }
    }

    System.out.print(cnt);
  }

}

 

1088. 3의 배수는 통과?

import java.io.*;

public class codeup1088 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int a = Integer.parseInt(br.readLine());

    for (int i = 1; i <= a; i++) {

      if (i % 3 != 0) {
        System.out.print(i + " ");
      }
    }
  }

}

 

1089. 수 나열하기 1

import java.io.*;
import java.util.*;

public class codeup1089 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    List<Integer> data = new ArrayList<Integer>();
    String array[] = br.readLine().split(" ");

    int a = Integer.parseInt(array[0]);
    int d = Integer.parseInt(array[1]);
    int n = Integer.parseInt(array[2]);

    int sum = 0;

    for (int i = 0; i < n; i++) {
      if (i == 0) {
        sum = a + d * i;
        data.add(sum);
      } else if (i < n && i >= 1) {
        sum = sum + d;
        data.add(sum);
      } else {
        break;
      }
    }

    System.out.print(data.get(n - 1).toString());

  }

}

 

1090. 수 나열하기 2

import java.io.*;
import java.util.*;

public class codeup1090 {
  public static void main(String[] args) throws IOException {
    List<Long> data = new ArrayList<Long>();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String array[] = br.readLine().split(" ");

    int a = Integer.parseInt(array[0]);
    int r = Integer.parseInt(array[1]);
    int n = Integer.parseInt(array[2]);

    long sum = 0;

    for (int i = 0; i < n; i++) {
      if (i == 0) {
        sum = a;
        data.add(sum);
      } else if (i >= 1 && i < n) {
        sum *= r;
        data.add(sum);
      } else {
        break;
      }
    }

    System.out.print(data.get(n - 1).toString());

  }
}

 

1091. 수 나열하기 3

import java.io.*;
import java.util.*;

public class codeup1091 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    List<Long> data = new ArrayList<Long>();

    String array[] = br.readLine().split(" ");

    int a = Integer.parseInt(array[0]);
    int m = Integer.parseInt(array[1]);
    int d = Integer.parseInt(array[2]);
    int n = Integer.parseInt(array[3]);

    long sum = 0;

    for (int i = 0; i < n; i++) {
      if (i == 0) {
        sum = a;
        data.add(sum);
      } else if (i >= 1 && i < n) {
        sum = sum * m + d;
        data.add(sum);
      } else {
        break;
      }
    }

    System.out.print(data.get(n - 1).toString());

  }

}

 

1092. 함께 문제 푸는 날

import java.io.*;

public class codeup1092 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String array[] = br.readLine().split(" ");

    int p1 = Integer.parseInt(array[0]);
    int p2 = Integer.parseInt(array[1]);
    int p3 = Integer.parseInt(array[2]);

    int reg = 1;

    while (true) {
      reg++;

      if (reg % p1 == 0 && reg % p2 == 0 && reg % p3 == 0) {
        break;
      }
    }

    System.out.print(reg);

  }

}

 

728x90
반응형