728x90
반응형
728x90
반응형

카카오톡 모의 문제입니다.

1번

 
import java.util.Scanner;

public class Test {
/*	문제1
	자연수 N이 주어지면, N의 각 자릿수의 합을 구해서 return 하는 solution 함수를 만들어 주세요.
	예를들어 N = 123이면 1 + 2 + 3 = 6을 return 하면 됩니다.

	제한사항 
	N의 범위 : 100,000,000 이하의 자연수
*/
	public static int solution(int n) {
		int answer = 0;
        while(n>0){
            answer += (n%10);
            n = n/10;
        }
		return answer;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		System.out.println("자릿수의 합 : " +solution(a));
	}

}
 

2번

 
import java.util.Scanner;

public class Test {
/* 문제2	
 * 길이가 n인 배열에 1부터 n까지 숫자가 중복 없이 한 번씩 들어 있는지를 확인하려고 합니다.
	1부터 n까지 숫자가 중복 없이 한 번씩 들어 있는 경우 true를, 아닌 경우 false를 반환하도록 함수 solution을 완성해주세요.

	제한사항
	배열의 길이는 10만 이하입니다.
	배열의 원소는 10만 이하의 자연수입니다.
*/
	public static boolean solution(int[] arr) {
        boolean answer = true;
        int[] chk = new int[arr.length+1];
        for(int i=0; i<arr.length; i++) {
        	if(arr[i]<1 || arr[i]>arr.length) { //n이하의 자연수여야 함으로 arr[i]값이 arr.length보다 크면 false
        		answer = false;
        		return answer;
        	}
        	chk[arr[i]]++; //chk배열을 통해 n이하의 자연수가 있는 지 확인
        }
        for(int i=1; i<=arr.length; i++) {
        	if(chk[i]>1) {
        		answer = false;
        		return answer;
        	}
        }
        return answer;	
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int arr[] = new int[a];
		for(int i=0; i<a; i++) {
			arr[i] = (int) (Math.random()*10)+1;
			//System.out.print(arr[i]+ " ");
		}
		System.out.println("결과는 " +solution(arr));
	}

}
 

3번

 
public class Test {
/* 문제3	
 * 직사각형을 만드는 데 필요한 4개의 점 중 3개의 좌표가 주어질 때, 나머지 한 점의 좌표를 구하려고 합니다. 
 * 점 3개의 좌표가 들어있는 배열 v가 매개변수로 주어질 때, 직사각형을 만드는 데 필요한 나머지 한 점의 좌표를 return 하도록 solution 함수를 완성해주세요. 
 * 단, 직사각형의 각 변은 x축, y축에 평행하며, 반드시 직사각형을 만들 수 있는 경우만 입력으로 주어집니다.
 * 
 * 제한사항
	v는 세 점의 좌표가 들어있는 2차원 배열입니다.
	v의 각 원소는 점의 좌표를 나타내며, 좌표는 [x축 좌표, y축 좌표] 순으로 주어집니다.
	좌표값은 1 이상 10억 이하의 자연수입니다.
	직사각형을 만드는 데 필요한 나머지 한 점의 좌표를 [x축 좌표, y축 좌표] 순으로 담아 return 해주세요.
*/
	public int[] solution(int[][] v) {
        int[] answer = {0,0};
        for(int i=0; i<3; i++) { //3개의 점에 대해 수행하기에 반복문을 3번 돌린다.
        	answer[0] ^= v[i][0]; //x좌표는 주어진 좌표에 x좌표를 xor하고
        	answer[1] ^= v[i][1]; //y좌표는 주어진 좌표에 y좌표를 xor하면 나머지 한 점의 좌표가 들어가게 된다.
        }
        return answer;
    }
}
 

4번

 
/*문제4 
   * 1와 0로 채워진 표(board)가 있습니다. 표 1칸은 1 x 1 의 정사각형으로 이루어져 있습니다. 
	 * 표에서 1로 이루어진 가장 큰 정사각형을 찾아 넓이를 return 하는 solution 함수를 완성해 주세요. 
	 * (단, 정사각형이란 축에 평행한 정사각형을 말합니다.)
		
	제한사항
		표(board)는 2차원 배열로 주어집니다.
		표(board)의 행(row)의 크기 : 1000 이하의 자연수
		표(board)의 열(column)의 크기 : 1000 이하의 자연수
		표(board)의 값은 1또는 0으로만 이루어져 있습니다.
	*/
	int dp[][] = new int[1001][1001];
	public int solution(int[][] board){
		int answer=0;
	    for(int i=1; i<=board.length; i++){
	    	for(int j=1; j<=board[0].length; j++){
	    		if(board[i-1][j-1] != 0){
	    			dp[i][j] = Math.min(dp[i][j-1], Math.min(dp[i-1][j], dp[i-1][j-1])) + 1;
	                answer = Math.max(answer, dp[i][j]);
	            }
	        }
	    }
	    return answer*answer;
	}
}
 
728x90
반응형
728x90
반응형

이클립스의 기본 테마가 지루하신 분들을 위해 테마 변경에 대해 소개해드리려고 합니다.

1. 이클립스 테마 코딩 부분만 변경하기

이클립스를 설치하셨다는 가정하에 설명해드릴게요.

1.1 메뉴 - Help - Eclipse Marketplace로 들어가주세요

또는 오른쪽 위에 Eclipse Marketplace 검색하여 들어가도 됩니다.

1.2 color theme 검색 후 엔터를 쳐주세요.

1.3 Eclipse Color Theme가 보이셨다면 Install해주세요.

1.4 설치하셨다면 메뉴 - Window - Preferences로 들어가주세요.

1.5 General - Appearance - Color Theme로 들어가서 원하는 테마를 선택하여 Apply하면 됩니다.

2. 이클립스 테마 전체 변경하기

2.1 메뉴 - Window - Preferences로 들어가주세요.

2.2 General - Appearance를 클릭해 Theme - Dark로 변경하면 전체 영역이 변경됩니다.

(Light는 기본 테마로 변경해줍니다.)



728x90
반응형
728x90
반응형

문제는 다음과 같습니다. 

https://www.acmicpc.net/problem/11053

문제 이해부터가 힘드네요....

가장 긴 증가하는 부분 수열이라....

주어진 수열 중에서 증가하는 수열의 길이를 가장 길게 만들어라??라는 의미인데요.




  
import java.util.Scanner;
 
public class Test11053 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //수열의 크기 N, N크기의 수열 arr[], 증가하는 부분 수열의 길이 dp[i]
        int N = sc.nextInt();
        int arr[] = new int[N];
        for(int i=0; i<N; i++){
        arr[i] = sc.nextInt();
        }
        int max=1;
        int dp[] = new int[N];
        for(int i=0; i<N; i++){
            dp[i]=1;
            for(int j=0; j<i; j++){
                if(arr[i]>arr[j] && dp[i]<=dp[j]){
                    dp[i]+=1;
                    if(max<dp[i]){
                        max = dp[i];
                    }
                }
            }
        }
        System.out.println(max);
        sc.close();
    }
}
 


결과는 다음과 같습니다.



728x90
반응형
728x90
반응형

문제는 다음과 같습니다.

https://www.acmicpc.net/problem/6359



  
import java.util.Scanner;

public class Test6359 {
    public static void main(String[] args) {
        //테스트 수 T, 방의개수 n, 방 room[], 열린 방의 수 cnt,라운드 round, 문 상태 door 
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int i=0; i<T; i++){
            int cnt=0;
            int n = sc.nextInt();
            boolean room[] = new boolean[n];
            for(int round=1; round<=n; round++){
                for(int door=0; door<n; door++){
                    if((door+1)%round==0){
                        if(room[door]==false){
                            cnt++;
                            room[door]=true;
                        }else{
                            cnt--;
                            room[door]=false;
                        }
                    }
                }
            }
        System.out.println(cnt);
        }
        sc.close();
    }
}
 


결과는 다음과 같습니다.


728x90
반응형
728x90
반응형

문제는 다음과 같습니다. 

https://www.acmicpc.net/problem/9095


 
import java.util.Scanner;
public class Test9095 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt(); //방법의 수를 테스트할 갯수
        int[] arr = new int[11];
		
        arr[1]=1; 
        arr[2]=2;
        arr[3]=4;
        //경우의 수 추출
        for(int i=0; i<T; i++){
            int n = sc.nextInt();
            for(int j=4; j<=n; j++){
                arr[j]=arr[j-3]+arr[j-2]+arr[j-1];
            }
            System.out.println(arr[n]);
        }

    }
}
 


결과는 다음과 같습니다.


728x90
반응형
728x90
반응형

문제는 다음과 같습니다.

https://www.acmicpc.net/problem/11399



 
import java.util.Scanner;

public class ATMTest {
	public static void main(String[] args){
		System.out.println("백준알고리즘 11399번 ATM");
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); //인원 수 입력
		int[] people = new int[N]; //배열 생성
		for(int i=0; i<N; i++){
			people[i] = sc.nextInt();
		}
		for(int i=0; i<people.length; i++){ //정렬
			for(int j=i+1; j<people.length; j++){
				if(people[i]>people[i+1]){
					int imsi = people[i];
					people[i] = people[i+1];
					people[i+1] = imsi;
				}
			}
		}
		int min=0;
		for(int i=0; i<people.length; i++){
			for(int j=0; j<=i; j++){
				min += people[j];
			}
		}
		System.out.println(min);
	}
}
 

결과는 다음과 같습니다.



728x90
반응형
728x90
반응형

문제는 다음과 같습니다.

https://www.acmicpc.net/step/4


 
import java.util.Scanner;

public class IfTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("========9498번========");
        int score = sc.nextInt();
        if(score>0 && score<=100){
            if(score>=90){
                System.out.println("A");
            }else if(score>=80 && score<90){
                System.out.println("B");
            }else if(score>=70 && score<80){
                System.out.println("C");
            }else if(score>=60 && score<70){
                System.out.println("D");
            }else{
                System.out.println("F");
            }
        }else{
            System.out.println("올바른 점수를 입력하세요.");
        }
    }
}
 

9498번 결과입니다.


   
import java.util.Scanner;

public class IfTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("========10817번========");
        int[] data = new int[3];
        for(int a=0; a<data.length; a++){
            data[a] = sc.nextInt();
        }
        for(int i=0; i<data.length;i++){
            for(int j=i+1; j<data.length; j++){
                if(data[i]>data[j]){
                    int imsi=data[i];
                    data[i]=data[j];
                    data[j]=imsi;
                }  //if end
            }  //for1 end
        }  //for2 end
        System.out.println(data[1]);
    }
}
 

10817번 결과입니다.

 
import java.util.Scanner;

public class IfTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("========10871번========");
        int n = sc.nextInt();
        int x = sc.nextInt();
        int data[] = new int[n];
		
        for(int i=0; i<data.length; i++){
            data[i] = sc.nextInt();
        } //for1 end
        for(int i=0; i<data.length; i++){
            if(data[i]<x){
                System.out.print(data[i]+" ");
            } //if end
        } //for2 end
    } //main end
} //class end
 

10871번 결과입니다.




 
import java.util.Scanner;

public class IfTest {
    public static void main(String[] args) {
        System.out.println("========1546번========");
        int n = sc.nextInt();
        int data[] = new int[n];
        for(int i=0; i<data.length; i++){
            data[i] = sc.nextInt();
        }
        double sum=0;
        double avg=0;
        for(int i=0; i<data.length;i++){
            for(int j=i+1; j<data.length; j++){
                if(data[i]>data[j]){
                    int imsi=data[i];
                    data[i]=data[j];
                    data[j]=imsi;
                }
            }System.out.print(data[i]+" ");
        }System.out.println();
        for(int i=0; i<data.length; i++){
            if(data[i]>0 && data[i]<=100){
                sum += (double) data[i]/data[data.length-1]*100;
            }else{
                System.out.println("정확한 점수를 입력하세요.");
            }
            avg = sum/data.length;
        }
        System.out.println("평균 : "+String.format("%.2f", avg));
    }
}
 

1546번 결과입니다.



728x90
반응형
728x90
반응형

문제는 다음과 같습니다.

https://www.acmicpc.net/step/3

 

 

 

  
import java.util.Scanner;

public class ForTestMain {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	System.out.println("8393==============");
    	System.out.print("수를 입력 : ");
    	int a = sc.nextInt();
    	int sum = 0;
    	for(int i=0; i<a; i++){
    		sum = sum + i;
    	}
    	System.out.println(a + "의 합 "+ sum);
    	System.out.println("11720==============");
    	int n = sc.nextInt();
    	String num = sc.next();
    	int result = 0;
    	for(int i=0; i<n; i++){
    		result = result + num.charAt(i) - 48;
    	}
    	System.out.println(result);
    	System.out.println("11721==============");
        String words = sc.next();
        if(words.length()>0 && words.length()<=100){  //0보다 크며 100길이를 넘지 않는 조건
            for(int i=0; i<=words.length(); i++){
                int x = i*10; //
                int y = x+10; //
                String word="";
                if(x==0){ 
                	word = words.substring(0, 10); //substring(), x부터 y전까지 위치의 문자열을 가져오는 함수
                	System.out.println(word);
                }else if(y<=words.length()){
                	word = words.substring(x, y);
                	System.out.println(word);
                }else{
                	word = words.substring(x, words.length());
                	System.out.println(word);
                	break;
                }
            }
        }else{
        	System.out.println("글자수를 초과하거나 부족합니다.");
        }
        
    }
}

 

결과는 다음과 같습니다.

 

 

728x90
반응형
728x90
반응형

+ Recent posts