Loading...

[백준] 1244번 스위치 켜고 끄기 (java)

여자의 경우 현재의 위치를 left, right 변수를 둬서 각각 왼쪽, 오른쪽으로 이동하며 비교해나간다. import java.util.Scanner; public class Main { static int n,m; static int[] light=new int[n]; static int[][] student=new int[m][2]; public static void main(String[] args) { Scanner sc=new Scanner(System.in); n=sc.nextInt(); light=new int[n]; for (int i = 0; i < n; i++) { light[i]=sc.nextInt(); } m=sc.nextInt(); student=new int[m][2]; for..

swexpert 1289. 원재의 메모리 복구하기 (java)

flag변수를 둬서 현재 또 바꿔야할 부분이 있는지 검사했습니다. 1. 모든 값이 000 이렇게 0인 상태에서 1로 바꾸는 것이 시작이니 flag를 1로 해서 1이 있는 곳을 검사합니다 2. 해당 위치의 문자를 1로 바꿨다고 가정하고 그 위치의 다음 인덱스부터 이번에는 0이 있는 곳이 있는지 검사합니다. 해당 위치부터 끝까지 숫자가 모두 1로 바뀌었으니 이제 flag변수는 0으로 바꿔줍니다. 3. 이제 더이상 바꿀 문자가 없을 때까지 진행하고 indexOf가 -1이 나오면 없다는 뜻이니 끝내줍니다 import java.util.Scanner; public class Solution { static int t; public static void main(String[] args) { Scanner sc=n..