Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 클린코드
- 알고리즘
- 부스트캠프
- Clean Code
- data science methodology
- 깨끗한 코드
- Coursera
- 문자열
- 데이터 사이언스
- 소프티어
- 프로그래머스
- IBM
- 데이터과학
- AI Mathematics
- 코테
- programmers
- 티스토리챌린지
- 오블완
- 클린코드 파이썬
- 데이터사이언스
- softeer
- 자바
- Java
- Boostcamp AI
- 파이썬
- Data Science
- string
- 코딩테스트
- Python
- 코세라
Archives
- Today
- Total
떼닝로그
[Java] Softeer 나무 공격 (배열) 본문
[Java] Softeer 나무 공격 (배열)
문제 링크 : https://softeer.ai/practice/9657
Softeer - 현대자동차그룹 SW인재확보플랫폼
softeer.ai
기록의 이유...
별 거 없다...
그냥 굉장히 지저분하게 푼 나의 코드 구경하라고... 글 올려본다...
입력 받을 땐 Scanner sc = new Scanner(System.in); 해줘야 한다
그리고 다행히 옛날에 C 했던 게 조금 남아있어서 배열 선언정도는 할 수 있다 (하핫)
등호 기준으로
- 왼쪽에는 자료형에 내가 구현하고 싶은 차원만큼 [] 개수 작성하고 변수 명 작성하고
- 오른쪽에는 new로 자료형 객체 생성, 그리고 [] 안에 배열 크기 작성해주면 된다
ex. int[][] board = new int[6][5];
배열 선언할 때 0으로 값 다 채우기 이런 게 옛날에 C에는 있었던 것 같은데, 자바는 잘 모르겠네,,, 물론 찾아보면 나올듯
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
int col = sc.nextInt();
int[][] board = new int[row][col];
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
board[i][j] = sc.nextInt();
}
}
int start1 = sc.nextInt();
int end1 = sc.nextInt();
int start2 = sc.nextInt();
int end2 = sc.nextInt();
int[] rowcnt = new int[row];
for(int i=0;i<row;i++){
rowcnt[i] = 0;
}
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(board[i][j] == 1)
rowcnt[i] += 1;
}
}
for(int i=start1-1;i<=end1-1;i++){
if(rowcnt[i] > 0)
rowcnt[i] -= 1;
}
for(int i=start2-1;i<=end2-1;i++){
if(rowcnt[i] > 0)
rowcnt[i] -= 1;
}
int result = 0;
for(int i=0;i<row;i++)
result += rowcnt[i];
System.out.print(result);
}
}
'Algorithms > Softeer' 카테고리의 다른 글
| [Java] Softeer 바이러스 (자료형 관리) (5) | 2024.10.31 |
|---|---|
| [Java] Softeer 금고 털이 (HashMap) (2) | 2024.10.31 |
| [Java] Softeer 나무 출력 - (출력 문자열 포함, StringBuilder) (4) | 2024.10.24 |
| [Java] Softeer 메리 크리스마스 - (출력 문자열 포함) (0) | 2024.10.24 |
| [Python] Softeer Lv2 - [한양대 HCPC 2023] X marks the Spot (Immutable String) (2) | 2024.08.04 |
Comments