Skip to content

PR : 2주차 문제 풀이 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/sgyj/inflearn/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@

***

***
## 2주차.
- 2-1
- [11. 문자열 압축](https://cote.inflearn.com/contest/10/problem/01-11)
- [12. 암호](https://cote.inflearn.com/contest/10/problem/01-12)
- [1. 큰 수 출력하기](https://cote.inflearn.com/contest/10/problem/02-01)
- [2. 보이는 학생](https://cote.inflearn.com/contest/10/problem/02-02)
- [3. 가위 바위 보](https://cote.inflearn.com/contest/10/problem/02-03)
- 2-2
- [4. 피보나치 수열](https://cote.inflearn.com/contest/10/problem/02-04)
- [5. 소수(에라토스테네스 체)](https://cote.inflearn.com/contest/10/problem/02-05)
- [6. 뒤집은 소수](https://cote.inflearn.com/contest/10/problem/02-06)
- [7. 점수계산](https://cote.inflearn.com/contest/10/problem/02-07)
- [8. 등수구하기](https://cote.inflearn.com/contest/10/problem/02-08)
***
28 changes: 28 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution11.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sgyj.inflearn.study.week2;

import java.util.Scanner;

public class Solution11 {

public String solution(String s){
String answer="";
s = s+ " ";
int cnt = 1;
for(int i=0; i<s.length()-1; i++){
if(s.charAt( i ) == s.charAt( i+1 )) cnt++;
else{
answer += s.charAt( i );
if(cnt > 1) answer+= String.valueOf( cnt );
cnt = 1;
}
}
return answer;
}

public static void main(String[] args){
Scanner in=new Scanner( System.in);
sgyj.inflearn.yeji.week2.Solution11 solution11 = new sgyj.inflearn.yeji.week2.Solution11();
System.out.println( solution11.solution( in.nextLine() ) );

}
}
28 changes: 28 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution12.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sgyj.inflearn.study.week2;

import java.util.Scanner;

public class Solution12 {
/*
* Integer.parseInt();
* */
public static String solution(int n , String s){
String answer = "";
for(int i=0; i<n; i++){
String tmp = s.substring( 0,7 ).replace( '#','1' ).replace( '*','0' );
int num = Integer.parseInt( tmp,2 );
answer+=(char)num;
s=s.substring( 7 );
}
return answer;
}

public static void main(String[] args){
Scanner in=new Scanner( System.in);
sgyj.inflearn.yeji.week2.Solution12 solution12 = new sgyj.inflearn.yeji.week2.Solution12();
int n = in.nextInt();
in.nextLine();
String s = in.nextLine();
System.out.println( solution12.solution( n, s ) );
}
}
28 changes: 28 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution13.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sgyj.inflearn.study.week2;

import java.util.ArrayList;
import java.util.Scanner;

public class Solution13 {
public ArrayList<Integer> solution( int n, int[] arr){
ArrayList<Integer> answer = new ArrayList<>();
answer.add( arr[0] );
for(int i=1; i<n; i++){
if(arr[i] > arr[i-1]) answer.add( arr[i] );
}
return answer;
}

public static void main(String[] args){
Solution13 solution13 = new Solution13();
Scanner kb = new Scanner( System.in );
int n = kb.nextInt();
int[] arr = new int[n];
for ( int i = 0; i < n; i++ ) {
arr[i] = kb.nextInt();
}
for(int x : solution13.solution(n,arr)){
System.out.print( x + " " );
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution14.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sgyj.inflearn.study.week2;

import java.util.Scanner;

public class Solution14 {

public static int solution(int n, int[] arr){
int answer = 1, max=arr[0];

for(int i=1; i<n; i++){
if(arr[i] > max) {
answer++;
max=arr[i];
}
}

return answer;
}

public static void main(String[] args){
Scanner in=new Scanner( System.in);
int input1 = in.nextInt();
int[] ints = new int[input1];
for(int i=0; i<input1; i++){
ints[i] = in.nextInt();
}
System.out.print(solution(input1, ints));
}

}
42 changes: 42 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution15.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package sgyj.inflearn.study.week2;

import java.util.Scanner;

public class Solution15 {

public static String solution(int n, int[] a, int[] b){
String answer = "";
for(int i=0; i<n; i++){
if(a[i] == b[i]){
answer+="D";
}else if(a[i] == 1 && b[i] == 3){
answer+="A";
}else if(a[i] == 2 && b[i] == 1){
answer+="A";
}else if(a[i] == 3 && b[i] == 2){
answer+="A";
}else{
answer+="B";
}
}

return answer;
}


public static void main(String[] args){
Scanner in=new Scanner( System.in);
int input1 = in.nextInt();
in.nextLine();
int[] input2 = new int[input1];
int[] input3 = new int[input1];
for(int i=0; i<input1; i++){
input2[i] = in.nextInt();
}
for(int i=0; i<input1; i++){
input3[i] = in.nextInt();
}
String solution = solution( input1, input2, input3 );
System.out.println(solution);
}
}
26 changes: 26 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution16.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sgyj.inflearn.study.week2;

import java.util.Scanner;

public class Solution16 {

public int[] solution(int n){
int[] answer = new int[n];
answer[0] = 1;
answer[1] = 1;

for(int i=2; i<n; i++){
answer[i] = answer[i-2] + answer[i-1];
}

return answer;
}

public static void main(String[] args){
Solution16 solution16 = new Solution16();
Scanner kb = new Scanner( System.in );
int n = kb.nextInt();
for(int x : solution16.solution(n)) System.out.print(x + " ");

}
}
27 changes: 27 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution17.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package sgyj.inflearn.study.week2;

import java.util.Scanner;

public class Solution17 {

public int solution(int n){
int answer = 0;
int[] ch = new int[n+1];
for(int i=2; i<=n; i++){
if(ch[i] == 0){
answer++;
for(int j=i; j<=n; j=j+1){
ch[j] = 1;
}
}
}
return answer;
}

public static void main(String[] args){
Solution17 solution17 = new Solution17();
Scanner scanner = new Scanner( System.in );
int n = scanner.nextInt();
System.out.print(solution17.solution(n));
}
}
45 changes: 45 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution18.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package sgyj.inflearn.study.week2;

import java.util.ArrayList;
import java.util.Scanner;

public class Solution18 {

public boolean isPrime(int num){
if(num == 1) return false;
for(int i=2; i<num; i++){
if(num % i ==0) return false;
}
return true;
}

public ArrayList<Integer> solution(int n , int[] arr){
ArrayList<Integer> answer = new ArrayList<>();

for(int i=0; i<n; i++){
int tmp = arr[i];
int res = 0;
while(tmp > 0){
int t = tmp % 10;
res = res * 10 + t;
tmp = tmp/10;
}
if(isPrime(res)) answer.add( res );
}

return answer;
}

public static void main(String[] args){
Solution18 solution18 = new Solution18();
Scanner scanner = new Scanner( System.in );
int n = scanner.nextInt();
int[] arr = new int[n];
for(int i=0; i<n; i++){
arr[i] = scanner.nextInt();
}
for(int x : solution18.solution(n, arr)){
System.out.print(x+" ");
}
}
}
34 changes: 34 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution19.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package sgyj.inflearn.study.week2;

import java.util.Scanner;

public class Solution19 {

public int solution(int n, int[] arr){
int answer = 0, cnt = 0;
for(int i=0; i<n; i++){
if(arr[i] == 1){
cnt++;
answer+=cnt;
}else{
cnt=0;
}
}

return answer;
}

public void main(String[] args){
Solution19 solution19 = new Solution19();
Scanner scanner = new Scanner( System.in );
int n = scanner.nextInt();

int[] arr = new int[n];

for(int i=0; i<n; i++){
arr[i] = scanner.nextInt();
}

System.out.print(solution19.solution(n, arr));
}
}
30 changes: 30 additions & 0 deletions src/main/java/sgyj/inflearn/study/week2/Solution20.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sgyj.inflearn.study.week2;

import java.util.Scanner;

public class Solution20 {
public int[] solution(int n, int[] arr){
int[] answer = new int[n];

for(int i=0; i<n; i++){
int cnt = 1;
for(int j=0; j<n; j++){
if(arr[j] > arr[i]) cnt++;
}
answer[i] = cnt;
}

return answer;
}

public void main(String[] args){
Solution20 solution20 = new Solution20();
Scanner scanner = new Scanner( System.in );
int n = scanner.nextInt();
int[] arr = new int[n];
for(int i=0; i<n; i++){
arr[i] = scanner.nextInt();
}
for(int x : solution20.solution(n, arr)) System.out.print(x + " ");
}
}
Loading