1978번: 소수 찾기
첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다.
www.acmicpc.net
import java.lang.reflect.Array;
import java.nio.charset.CoderResult;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int count = 0;
boolean ch = true;
for(int i= 0; i<num; i++){
int number = sc.nextInt();
if(number == 1) continue;
for(int k = 2; k<=Math.sqrt(number); k++){
if(number % k == 0){
ch = false;
break;
}
}
if(ch) count++;
ch = true;
}
System.out.println(count);
}
}
2609번: 최대공약수와 최소공배수
첫째 줄에는 입력으로 주어진 두 수의 최대공약수를, 둘째 줄에는 입력으로 주어진 두 수의 최소 공배수를 출력한다.
www.acmicpc.net
import java.lang.reflect.Array;
import java.nio.charset.CoderResult;
import java.util.*;
import java.io.*;
public class Main {
static int gcd (int a, int b) {
while (b > 0) {
int temp = a;
a = b;
b = temp % b;
}
return a;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(gcd(a,b));
System.out.println(a*b/gcd(a,b));
}
}
2798번: 블랙잭
첫째 줄에 카드의 개수 N(3 ≤ N ≤ 100)과 M(10 ≤ M ≤ 300,000)이 주어진다. 둘째 줄에는 카드에 쓰여 있는 수가 주어지며, 이 값은 100,000을 넘지 않는 양의 정수이다. 합이 M을 넘지 않는 카드 3장
www.acmicpc.net
import java.io.*;
import java.nio.Buffer;
import java.util.*;
public class B2_2798 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int arr_size = 1;
for(int i = 0 ; i<3; i++){
arr_size *= n-i;
}
arr_size = arr_size/6;
int[] target = new int[m];
StringTokenizer st2 = new StringTokenizer(br.readLine());
for(int i = 0; i<n; i++){
target[i] = Integer.parseInt(st2.nextToken());
}
int[] arr = new int[arr_size];
int y = 0;
for(int i = 0; i<n; i++){
for(int j = i+1; j<n; j++){
for(int k = j+1; k<n; k++){
arr[y] = target[i]+target[j]+target[k];
y++;
}
}
}
int max = 0;
Arrays.sort(arr);
for(int i = arr.length-1; i>=0; i--){
max = arr[i];
if(arr[i]<=m) break;
}
bw.write(String.valueOf(max));
bw.flush();
bw.close();
}
}
8958번: OX퀴즈
"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수
www.acmicpc.net
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for (int k = 0; k < num; k++) {
String[] arr = sc.next().split("");
int count = 0;
int sum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i].equals("O")) count++;
else {
count = 0;
}
sum += count;
}
System.out.println(sum);
sum = 0;
count = 0;
}
}
}
11650번: 좌표 정렬하기
첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.
www.acmicpc.net
import java.lang.reflect.Array;
import java.nio.charset.CoderResult;
import java.util.*;
import java.io.*;
class Coordinate implements Comparable<Coordinate>{
int x;
int y;
Coordinate(int x, int y){
this.x = x;
this.y = y;
}
@Override
public int compareTo(Coordinate o) {
if(o.x == this.x) return this.y - o.y;
else return this.x - o.x;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
Coordinate[] arr = new Coordinate[num];
for(int i = 0; i<num; i++){
arr[i] = new Coordinate(sc.nextInt(),sc.nextInt());
}
Arrays.sort(arr);
for(int i = 0; i<num; i++){
System.out.println(arr[i].x +" "+ arr[i].y);
}
}
}
한 문제에서 막혀서 생각보다 많이는 못풀었다
실버 문제도 고민해서 풀어야 하는 경우가 많아서 걱정된다 그래도 랭크 올라가는게 재밌어서 열심히하게되어서 다행이다
이번에 solved.ac에서 블랙잭 이벤트가 열려서 열심히 하고 있다.
소수 문제를 풀면서 1학년때 배웠던 것 같은 에라토스테네스의 체 알고리즘을 복습하고 최대공약수 최소공배수 문제를 풀면서 유클리드 호제법에 대해 새로 알게 되었다.
'모각코 > 2022 하계 모각코' 카테고리의 다른 글
20220817 6주차 [진저비어] 모각코 계획 (0) | 2022.08.19 |
---|---|
20220810 5주차 [진저비어] 모각코 결과 (0) | 2022.08.10 |
20220810 5주차 [진저비어] 모각코 계획 (0) | 2022.08.10 |
220802 4주차 [진저비어] 모각코 결과 (0) | 2022.08.03 |
220802 4주차 [진저비어] 모각코 계획 (0) | 2022.08.03 |