스터디 - 2

업데이트:


[1405] 숫자 로테이션

[입력]
5
1 2 3 4 5
[출력]
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = sc.nextInt();
		}
		int idx = 0;
		for (int i = 0; i < arr.length; i++) {
			idx = i;
			for (int j = 0; j < arr.length; j++) {
				if(idx != arr.length-1)
					System.out.print(arr[idx++] + " ");
				else if(idx == arr.length - 1) {
					System.out.print(arr[idx] + " ");
					idx = 0;
				}
			}
			System.out.println();
		}
	}
}



[1410] 올바른 괄호 1 (괄호 개수 세기)

[입력] ((())()(()))
[출력] 6 6

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		int c1 = 0;
		int c2 = 0;
		char[] c = new char[str.length()];
		for(int i = 0; i < str.length(); i++) {
			c[i] = str.charAt(i);
			if(c[i] == '(') c1++;
			else if(c[i] == ')') c2++;
		}
		System.out.println(c1 + " " + c2);
	}
}



태그: ,

카테고리:

업데이트:

댓글남기기