JAVA/JAVA Algorithm, Datastruct

[Algorithm] JAVA 코드업 기초 100제 (기초-1차원배열, 2차원배열) 1093 ~ 1099

큐범 2022. 9. 6. 02:50

1093 : [기초-1차원배열] 이상한 출석 번호 부르기1(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.nextLine();
		String s2 = sc.nextLine();
		
		int[] array = new int[23];
		int[] call = Arrays.stream(s2.split(" "))
				.mapToInt(Integer::parseInt)
				.toArray();
		
		for(int i=0; i<Integer.parseInt(s1); i++) {
			array[call[i]]++;
		}
		
		for(int j=1; j<23; j++) {
			System.out.print(array[j]+" ");
		}
	}

1094 : [기초-1차원배열] 이상한 출석 번호 부르기2(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int s1 = sc.nextInt();
		int[] array = new int[s1];

		
		for(int i =0; i<s1; i++) {
			array[i] = sc.nextInt();
		}
		
		for(int j = array.length-1; j>=0; j-- ) {
			System.out.print(array[j]+" ");
		}
	}

1095 : [기초-1차원배열] 이상한 출석 번호 부르기3(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int s1 = sc.nextInt();
		int[] array = new int[s1];

		
		for(int i =0; i<s1; i++) {
			array[i] = sc.nextInt();
		}
		
		int min=23;
		
		for(int j=0; j<array.length; j++) {
			if(array[j]<min) min= array[j];
		}
		
		System.out.println(min);
	}

1096 : [기초-2차원배열] 바둑판에 흰 돌 놓기(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[][] array = new int[19][19];
		
		for(int i=0; i<n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			array[x][y]=1;
		}
		
		for(int j=1; j<array.length; j++) {
			for(int k=1; k<array.length; k++) {
				System.out.print(array[j][k]);
			}
			System.out.print("\\n");
		}
	}

1097 : [기초-2차원배열] 바둑알 십자 뒤집기(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[][] array = new int[20][20];
		
		for(int i=1; i<array.length; i++) {
			for(int j=1; j<array.length; j++) {
				array[i][j]=sc.nextInt();	
			}
		}
		
		int n = sc.nextInt(); 
		
		for(int i=0; i<n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			for(int j=1; j<array.length; j++) {
				if(array[x][j]==0) array[x][j]=1;
				else array[x][j]=0;
			}
			for(int k=1; k<array.length; k++) {
				if(array[k][y]==0) array[k][y]=1;
				else array[k][y]=0;
			}
		}
		
		
		for(int j=1; j<array.length; j++) {
			for(int k=1; k<array.length; k++) {
				System.out.print(array[j][k]);
			}
			System.out.print("\\n");
		}
	}

1098 : [기초-2차원배열] 설탕과자 뽑기

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[][] array;
		
		int h,w,n,l,d,x,y; 
		h=sc.nextInt();
		w=sc.nextInt();
		
		array=new int[h][w];
		
		n=sc.nextInt();
		
		for(int i=0; i<n; i++) {
			l=sc.nextInt();
			d=sc.nextInt();
			x=sc.nextInt();
			y=sc.nextInt();
			
			for(int j=0; j<l; j++) {
				if(d==0) array[x-1][y-1+j]=1;
				else array[x-1+j][y-1]=1;
			}
		}
		
		for(int i=0; i<w; i++) {
			for(int j=0; j<w; j++) {
				System.out.print(array[i][j]+" ");
			}
			System.out.print("\\n");
		}
	}

1099 : [기초-2차원배열] 성실한 개미

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[][] array=new int[11][11];
		
		for (int i=1; i<=10; i++) {
			for (int j=1; j<=10; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		
		int x = 2;
		int y = 2;
		
		while(true) {
			if(array[x][y]==0) {
				array[x][y]=9;
				y++;
			}
			if(array[x][y]==1) {
				y--;
				x++;
			}
			if(array[x][y]==2) {
				array[x][y]=9;
				break;
			}else if(array[x][y]+1 ==1 && array[x+1][y]==1) {
				if(array[x][y]==0) array[x][y]=9;
				
				break;
			}
		}
		
		for(int i=1; i<=10; i++) {
			for(int j=1; j<=10; j++) {
				System.out.print(array[i][j]+" ");
			}
			System.out.print("\\n");
		}
	}