알고리즘/SwExpert recipe

SWEA 지그재그 숫자 [D2]

컵라면만두세트 2021. 2. 9. 23:33
package D2;

import java.util.Scanner;

public class 지그재그숫자 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int tc=1; tc<=T; tc++) {
		int N = sc.nextInt(); // 숫자 입력값
		int result = 0; // 결과값
		for(int i=1; i<=N; i++) {
			if(i%2 == 0) {
				result -= i;
				
			}else {
				result += i;
			}
		}
		System.out.println("#" + tc + " " + result);
		}
	}

}

'알고리즘 > SwExpert recipe' 카테고리의 다른 글

SWEA 초심자의회문검사 [D2]  (0) 2021.02.12
SWEA 새로운 불면증 치료 [D2]  (0) 2021.02.11
SWEA 암호문1 [D3]  (0) 2021.02.09
SWEA 간단한소인수분해 [D2]  (0) 2021.02.09
SWEA 한빈빈이와spotmar [D3]  (0) 2021.02.09