Post

baekjoon 2단계 조건문

기록용 baekjoon 단계별 풀이입니다. 언어 : Java

1330번


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.*;  
import java.io.*;  
public class Main {  
    public static void main(String[] args) throws IOException {  
          BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));  
        //키보드 입력 바이트 스트림을 char 타입으로 처리 후, string 타입으로 변환 후 저장  
	    StringTokenizer st = new StringTokenizer(bf.readLine()," ");  
        //readLine()으로 한 줄 입력 받고 토큰을 공백을 기준으로 나눔  
	    int A = Integer.parseInt(st.nextToken()); //첫번째 토큰 형변환(string->int) 후 입력 받음  
	    int B = Integer.parseInt(st.nextToken()); //두번째 토큰 형변환(string->int) 후 입력 받음  
  
	    System.out.println(A>B ? ">" : A<B ? "<" : "==");  
        // A>B 일 때 > 출력, A<B일 때 < 출력, 모든 조건이 아닐 때 == 출력  
	  }  
}


9498번


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.io.*;  
public class Main {  
    public static void main(String[] args) throws IOException {  
          BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));  
        //키보드 입력 바이트 스트림을 char 타입으로 처리 후, string 타입으로 변환하여 저장  
	    int score = Integer.parseInt(bf.readLine()); //한 줄 입력 받아 형변환(string->int) 후 출력  
	    String grade=""; //성적을 저장할 변수 초기화  
	    if(score>=90 && score <=100){ //90~100점일 때  
		    grade ="A"; //A문자 출력  
	     }  
        else if(score>=80){ //80~89일때  
		    grade ="B";  
        }  
        else if(score>=70){  
            grade ="C";  
        }  
        else if(score>=60){  
            grade ="D";  
        }  
        else{  
            grade ="F";  
        }  
        System.out.println(grade);  
    }  
}


2753번


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.io.*;  
public class Main {  
    public static void main(String[] args) throws IOException {  
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));  
        //키보드 입력 바이트 스트림을 char 타입으로 처리 후, string 타입으로 변환 후 저장  
	    int y = Integer.parseInt(bf.readLine()); //한 줄을 형변환(string->int)하여 입력 받고 저장  
	    if((y%4==0 && y%100!=0)||(y%400==0)) //4배수이면서(and) 100의 배수가 아닐 때 또는(or) 400의 배수일 때  
	      {  
            System.out.println("1"); //윤년일 때 1출력  
	      }  
           else { //그 외의 경우일 때   
		   System.out.println("0"); //0출력  
		     }  
    }  
}


14681번


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.io.*;  
public class Main {  
    public static void main(String[] args) throws IOException {  
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));  
        //키보드 입력 바이트 스트림을 char 타입으로 처리 후, string 타입으로 변환하여 출력  
        int x = Integer.parseInt(bf.readLine()); //한 줄 형변환하여 입력 받음  
        int y = Integer.parseInt(bf.readLine()); //한 줄 형변환하여 입력  받음  
  
        if(x>0 && y>0) //x,y가 양수일때  
        {  
            System.out.println("1"); //1출력  
         }  
        else if(x<0 && y>0) //x가 음수, y가 양수일 때  
         {  
            System.out.println("2");  
        }  
        else if(x<0 && y<0)  
        {  
            System.out.println("3");  
        }  
        else  
        {  
            System.out.println("4");  
        }  
    }  
}


2884번 - 다시


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.*;  
import java.io.*;  
public class Main {  
    public static void main(String[] args) throws IOException {  
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));  
        //키보드 입력 스트림을 char 타입으로 처리 후, string 타입으로 변환 후 저장  
  StringTokenizer st = new StringTokenizer(bf.readLine()," ");  
        //readLine()으로 한 줄을 입력 받고 토큰을 공백으로 구분함  
	    int h = Integer.parseInt(st.nextToken()); //첫번째 토큰 입력  
	    int m = Integer.parseInt(st.nextToken()); //두번째 토큰 입력  
  
	    if(m<45) //분이 45분보다 작을 경우  
	    {  
            h--; //시 감소  
		    m=60-(45-m); //분 감소  
	       if(h<0) //시가 0보다 작을 경우  
		  {  
                h=23; //23으로 시작  
		  }  
           System.out.println(h+" "+m);  
           }  
           else  
	    {  
            System.out.println(h+" "+(m-45));  
        }  
    }  
}


2525번 - 다시


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.*;  
import java.io.*;  
public class Main {  
    public static void main(String[] args) throws IOException {  
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));  
        //키보드 입력 바이트 스트림을 char 타입으로 처리 후, string 타입으로 변환하여 저장  
	    StringTokenizer st = new StringTokenizer(bf.readLine()," ");  
        //readLine()으로 한 줄 입력받고 공백을 기준으로 구분  
	    int h = Integer.parseInt(st.nextToken()); //첫번째 토큰을 입력  
	    int m = Integer.parseInt(st.nextToken()); //두번째 토큰을 입력  
	    int p = Integer.parseInt(bf.readLine()); // 한 줄 입력 받음  
  
	    m = m+p; //총 분(minute)을 구하기 위해 분에 더하는 수의 합  
  
	    while(m>=60) //분이60이 넘어갈 경우 계속 반복  
	  {  
            h++; //시 증가  
		    m=m-60; //총 분에 60을 뺄셈  
		    if(h>=24){ //시가 24시보다 클 경우  
			    h=h-24;   
            }  
        }  
        System.out.println(h+" "+m);  
    }  
}


2480번 - 다시


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.*;  
import java.io.*;  
public class Main {  
    public static void main(String[] args) throws IOException {  
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));  
        //키보드 입력 바이트 스트림을 char 타입으로 처리 후, string 타입으로 변환 후 저장  
  StringTokenizer st = new StringTokenizer(bf.readLine()," ");  
        //readLine()으로 한 줄을 입력 받고 공백을 기준으로 구분  
  int a = Integer.parseInt(st.nextToken()); //첫번째 토큰을 입력 받음  
  int b = Integer.parseInt(st.nextToken()); //두번째 토큰을 입력 받음  
  int c = Integer.parseInt(st.nextToken()); //세번째 토큰을 입력 받음  
  
  if(a==b && a==c)  
        {  
            System.out.println(10000+a*1000);  
        }  
        else if(a==b && a!=c || a==c && a!=b)  
        {  
            System.out.println(1000+a*100);  
        }  
        else if(b==c && a!=b)  
        {  
            System.out.println(1000+b*100);  
        }  
        else{  
            int max = a;  
            if(max<b)  
            {  
                max = b;  
            }  
            if(max<c)  
            {  
                max = c;  
            }  
            System.out.println(max*100);  
        }  
    }  
}
This post is licensed under CC BY 4.0 by the author.