반응형

1. 문제 번호 2525번


 

2. 한 줄 키워드 

 - 입력값 시간,분을 합산한 분(=totalMinutes)으로 변경

 - totalMinutes >= 1440 일때는 %24로 만들어줌

 


나의 문제풀이 방식 및 순서

 - 앞선 2884번과 동일



3. 소스 인증

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

/**********************

Writer : KTH
Purpose: 

**********************/

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine()," ");

        int I_hh = Integer.parseInt(st.nextToken()); //공백열 구분
        int I_mm = Integer.parseInt(st.nextToken());
        int targetWorkTime = Integer.parseInt(br.readLine()); //Enter 구분
        
        int totalMinutes = I_hh * 60 + I_mm;
        int targetMinutes = totalMinutes + targetWorkTime;

        if(targetMinutes>=1440){
            targetMinutes -= 24*60;
        }

        int resultHour = targetMinutes / 60 ;
        int resultMinutes = targetMinutes % 60;
        
        System.out.println(resultHour+" "+resultMinutes);

    }
}

4. 추가 개념

 

 

 

 

728x90
반응형

'알고리즘(BOJ) 문제풀이' 카테고리의 다른 글

[BOJ/백준] 조건문_2480번  (0) 2024.05.07
[BOJ/백준] 조건문_2884  (0) 2024.05.07
[BOJ/백준] 조건문_14681  (0) 2024.05.03
[BOJ/백준] 조건문_2753  (0) 2024.05.03
[BOJ/백준] 조건문_9498  (0) 2024.05.03
반응형

1. 문제 번호 14681번


 

2. 한 줄 키워드 

 

나의 문제풀이 방식 및 순서


3. 소스 인증

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

/**********************

Writer : KTH
Purpose: 

**********************/

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

        if      (x > 0 && y > 0) xyName = 1;
        else if (x > 0 && y < 0) xyName = 4;
        else if (x < 0 && y > 0) xyName = 2;
        else if (x < 0 && y < 0) xyName = 3;
        else xyName = 0;

        System.out.print(xyName);
        
	}
}

4. 추가 개념

 

 

 

 

 

728x90
반응형

'알고리즘(BOJ) 문제풀이' 카테고리의 다른 글

[BOJ/백준] 조건문_2884  (0) 2024.05.07
[BOJ/백준] 조건문_2525  (0) 2024.05.07
[BOJ/백준] 조건문_2753  (0) 2024.05.03
[BOJ/백준] 조건문_9498  (0) 2024.05.03
[BOJ/백준] 조건문_1330번  (0) 2024.05.03
반응형

1. 문제 번호 2753번


 

2. 한 줄 키워드 

 

2.1 계산 하는 방식을 간단히 해야한다. (문제를 정확히 이해하고 복잡한 삼항 연산자보다 간단하게 나타내기) 


3. 소스 인증

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

/**********************

Writer : KTH
Purpose: 

**********************/

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

        if ( (year%4 == 0 && year%100 !=0) || ((year%400==0) && !(year%100==0 &&year%400!=0)) ){
            yearName = 1;
        }

        System.out.print(yearName);    
        
	}
}

 

 

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

/**********************

Writer : KTH
Purpose: 

**********************/

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

        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
            System.out.println("1"); // 윤년
        } else {
            System.out.println("0"); // 윤년이 아님
        }

        // System.out.print(year%4 == 0 ? (year%400 == 0 ? "1" : (year%100 ==0) ? "0" : "1" ) :"0");
        
	}
}

4. 추가 개념

 

 

 

 

 

 

728x90
반응형

'알고리즘(BOJ) 문제풀이' 카테고리의 다른 글

[BOJ/백준] 조건문_2525  (0) 2024.05.07
[BOJ/백준] 조건문_14681  (0) 2024.05.03
[BOJ/백준] 조건문_9498  (0) 2024.05.03
[BOJ/백준] 조건문_1330번  (0) 2024.05.03
[BOJ/백준] 입출력과 사칙연산_10172번  (0) 2024.05.03
반응형

1. 문제 번호 9498번


 

2. 한 줄 키워드 

 

2.1 항상 가독성을 높이기 위해 고민 ↑ 

2.2 char 에 값을 넣기 위해서는 'A' 작은 따옴표 사용 


3. 소스 인증

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

/**********************

Writer : KTH
Purpose: 

**********************/

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

        if      (classScore >= 90) classScoreGrade = 'A';
        else if (classScore >= 80) classScoreGrade = 'B';
        else if (classScore >= 70) classScoreGrade = 'C';
        else if (classScore >= 60) classScoreGrade = 'D';
        else                       classScoreGrade = 'F';
        
        System.out.print(classScoreGrade);
	}
}

4. 추가 개념

 

 

 

 

 

 

 

728x90
반응형
반응형

1. 문제 번호 1130번


 

2. 문제 풀이 

 

2.1 배열 int[] tempList = new int[st.countToken()]; 

2.2 ArrayList : get() add()

2.3 삼항 연산자로 가독성 ↑ 

2.4 Split 또는 StringTokenizer.nextToken() 둘 중에 하나 사용

2.5 int[] numList = Integer.parseInt(br.readLine().split(" ")); 실패


3. 소스 인증

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

/**********************

Writer : KTH
Purpose: 

**********************/

public class Main {
	public static void main(String[] args) throws IOException {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<Integer> numList = new ArrayList<>();
        StringTokenizer st;

        st = new StringTokenizer(br.readLine());
        // int[] tempList = new int[st.countToken()]; 

        while(st.hasMoreTokens()){
            numList.add(Integer.parseInt(st.nextToken()));
        }

        System.out.print(numList.get(0)>numList.get(1) ? ">" : numList.get(0)<numList.get(1)? "<" : "==");
        
	}
}

 

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

/**********************

Writer : KTH
Purpose: 

**********************/

public class Main {
	public static void main(String[] args) throws IOException {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        // int[] numList = Integer.parseInt(br.readLine().split(" "));
        String[] str = br.readLine().split(" ");
        int A = Integer.parseInt(str[0]);
        int B = Integer.parseInt(str[1]);
		
        System.out.println((A>B) ? ">" : ((A<B) ? "<" : "==" ));
        
	}
}

4. 추가 개념

 

int[] numList = Integer.parseInt(br.readLine().split(" "));

Integer.parseInt( )인터페이스는 배열을 받을 수 있게 구현되어 있지 않다.

1. 점 표기법(Dot notation)

    - 객체 이름 작성 후 점(.) 을 사용하여 객체의 속성 또는 메서드에 접근

2. 메서드 호출 

    - 메서드 이름 뒤에 소괄호 사용

3. 메서드 체인

    - 여러 메서드 호출을 한 줄에 나열할 수 있다.

    - br.readLine().split(" ")에서 readLine() 메서드 결과에 대해 split(" ") 메서드를 호출

 

728x90
반응형
반응형

1. 문제 번호 10172번


 

2. 문제 풀이 

 

2.1 이스케이프 ("",\, 등등 은 단독으로 사용불가) 그래서 \ + 문자조합으로 사용필요

       - 그냥 시간 싸움이라서 안품


3. 소스 인증

public class Main {
	public static void main(String[] args) {
		System.out.println("|\\_/|");
		System.out.println("|q p|   /}");
		System.out.println("( 0 )\"\"\"\\");
		System.out.println("|\"^\"`    |");
		System.out.println("||_/=\\\\__|");     
        
        
/* 그 외의 방법들
		System.out.print(
        "|\\_/|\n" + 
		"|q p|   /}\n" + 
		"( 0 )\"\"\"\\\n" + 
		"|\"^\"`    |\n" + 
		"||_/=\\\\__|");
                         
		System.out.printf("%s", "|\\_/|\n
  		|q p|   /}\n
 		( 0 )\"\"\"\\\n
		|\"^\"`    |\n
		||_/=\\\\__|");
        
*/
	}
}

 

public class Main {
	public static void main(String[] args){
 
		StringBuffer sb = new StringBuffer();
		sb.append("|\\_/|\n");
		sb.append("|q p|   /}\n");
		sb.append("( 0 )\"\"\"\\\n");
		sb.append("|\"^\"`    |\n");    
		sb.append("||_/=\\\\__|\n"); 
		
		System.out.println(sb);
	}
}

4. 추가 개념

728x90
반응형
반응형

1. 문제 번호 10171번


 

2. 문제 풀이 

 

2.1 이스케이프 ("",\, 등등 은 단독으로 사용불가) 그래서 \ + 문자조합으로 사용필요

       - 그냥 시간 싸움이라서 안품


3. 소스 인증

public class Main {
	public static void main(String[] args){
 
		StringBuilder sb = new StringBuilder();
		sb.append("\\    /\\\n");
		sb.append(" )  ( ')\n");
		sb.append("(  /  )\n");
 		sb.append(" \\(__)|\n");
		
		System.out.println(sb);
	}
}

 

public class Main {
	public static void main(String[] args) {
    
		System.out.println("\\    /\\");
		System.out.println(" )  ( ')");
		System.out.println("(  /  )");
		System.out.println(" \\(__)|");    
 
	}
}

4. 추가 개념

728x90
반응형
반응형

1. 문제 번호 2588번


 

2. 문제 풀이 

 

2.1 입력값 원인으로 br.leadLine() 2개로 받는다.


3. 소스 인증

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

/**********************

Writer : KTH
Purpose: 

**********************/

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) throws IOException  {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<Integer> numList = new ArrayList<>();

        numList.add(Integer.parseInt(br.readLine()));
        numList.add(Integer.parseInt(br.readLine()));

        //각 값들을 변수에 저장
        int A = numList.get(0);
        int B = numList.get(1);

        // 요구되는 연산을 수행하고 결과를 출력
        System.out.println(A*(B%10));
        System.out.println(A*((B/10)%10)) ;
        System.out.println(A*(B/100));
        System.out.println(A*B);

        
    }
}

4. 추가 개념

728x90
반응형

+ Recent posts