본문 바로가기

Backend/JAVA

[Algorithm] 데일리 백준

반응형
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

public class Main {

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    StringBuilder sb = new StringBuilder();

//    10807
//    int listSize = Integer.parseInt(br.readLine());
//
//    String[] numbers = br.readLine().split(" ");
//
//    int checkNum = Integer.parseInt(br.readLine());
//    int count = 0;
//    for(int i = 0 ; i < listSize ; i++){
//      if(Integer.parseInt(numbers[i]) == checkNum){
//        count++;
//      }
//    }
//
//    System.out.println(count);

//    10871
//    String[] testCase = br.readLine().split(" ");
//
//    int listSize = Integer.parseInt(testCase[0]);
//    int checkNum = Integer.parseInt(testCase[1]);
//
//    String[] listNumbers = br.readLine().split(" ");
//
//    for (int i = 0; i < listSize; i++) {
//      if (Integer.parseInt(listNumbers[i]) < checkNum) {
//        sb.append(listNumbers[i] + " ");
//      }
//    }
//
//    System.out.println(sb);

//    10818
////    // 시간초과....
////    int testSize = Integer.parseInt(br.readLine());
////
////    String[] testCase = br.readLine().split(" ");
////
////    for(int i = 0 ; i < testSize ; i++){
//////      범위를 i만큼 하게 되면 가장 마지막 요소를 비교,정렬하지 않게 됨
//////      for(int j = 0 ; j < i ; j++){
////      for(int j = 0 ; j < testSize - 1 - i ; j++){
////        if(Integer.parseInt(testCase[j]) > Integer.parseInt(testCase[j+1])){
////          String temp = "";
////          temp = testCase[j+1];
////          testCase[j+1] = testCase[j];
////          testCase[j] = temp;
////        }
////      }
//////      반복 동작이 중복이라고 같은 반복문 안에서 출력하면 안됨 / 따로 처리 필요
//////      sb.append(testCase[i]+" ");
////    }
////    sb.append(testCase[0] + " " + testCase[testSize-1]);
////
////    System.out.println(sb);
//
//    int testSize = Integer.parseInt(br.readLine());
//
//    String[] testCase = br.readLine().split(" ");
//
//    String min = "";
//    String max = "";
//
//    // ArrayIndexOutOfBounds 방지
//    if(testCase.length > 2) {
//      min = testCase[0];
//      max = testCase[1];
//      for (int i = 0; i < testSize; i++) {
//        if (Integer.parseInt(min) > Integer.parseInt(testCase[i])) {
//          min = testCase[i];
//        }
//        if (Integer.parseInt(max) < Integer.parseInt(testCase[i])) {
//          max = testCase[i];
//        }
//      }
//    } else if(testCase.length == 2){
//      min = testCase[0];
//      max = testCase[1];
//      if(Integer.parseInt(max) < Integer.parseInt(min)){
//        String temp = "";
//        temp = max;
//        max = min;
//        min = max;
//      }
//    } else if(testCase.length == 1) {
//      max = testCase[0];
//      min = max;
//    }
//
//    sb.append(min + " " + max);
//
//    System.out.println(sb);

    // 2562
    String[] caseList = new String[9];
    for(int i = 0 ; i < 9 ; i++){
      String testCase = br.readLine();
      caseList[i] = testCase;
    }

    String max = caseList[0];
    int index = 0;
    for(int i = 0 ; i < 9 ; i++){
      if(Integer.parseInt(max) <= Integer.parseInt(caseList[i])){
        max = caseList[i];
        index = i+1;
      }
    }
    sb.append(max + "\n" + index);
    System.out.println(sb);


  }
}
반응형

'Backend > JAVA' 카테고리의 다른 글

[Algorithm] 데일리 백준  (0) 2024.04.30
[Algorithm] 데일리 백준  (0) 2024.04.29
[Algorithm] 데일리 백준  (0) 2024.04.24
[Algorithm] 데일리 백준  (0) 2024.04.12
[Algorithm] 데일리 백준  (0) 2024.04.09