최신판 |
당신의 편집 |
1번째 줄: |
1번째 줄: |
| ==개요== | | ==개요== |
| {{SWEA|난이도=2
| | ;SWEA 1986 지그재그 숫자 |
| |링크=https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PxmBqAe8DFAUq}}
| | * https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PxmBqAe8DFAUq |
| | |
| | {{SWEA 헤더}} |
| | {{SWEA 난이도 2-1}} |
| | |} |
|
| |
|
| ==C++== | | ==C++== |
| <syntaxhighlight lang='cpp'> | | <source lang='cpp'> |
| #include <iostream>
| | </source> |
| using namespace std;
| |
| int main() {
| |
| int T;
| |
| scanf("%d", &T);
| |
| int N;
| |
| for(int tc=1; tc<=T; tc++) {
| |
| scanf("%d", &N);
| |
| int sum = 0;
| |
| for(int i=1; i<=N; i++) {
| |
| if( i%2 == 0 ) sum -= i;
| |
| else sum += i;
| |
| }
| |
| printf("#%d %d\n", tc, sum);
| |
| }
| |
| }
| |
| </syntaxhighlight> | |
|
| |
|
| ==Java== | | ==Java== |
| <syntaxhighlight lang='java'> | | <source lang='java'> |
| import java.util.Scanner; | | import java.util.Scanner; |
| class Solution { | | class Solution { |
40번째 줄: |
28번째 줄: |
| } | | } |
| } | | } |
| </syntaxhighlight> | | </source> |
| | |
| ==Python==
| |
| <syntaxhighlight lang='python'>
| |
| #kcy
| |
| k = int(input())
| |
| for i in range(1, k+1):
| |
| n = int(input())
| |
| sum = 0
| |
| for j in range(1, n+1):
| |
| if j % 2== 0:
| |
| sum = sum - j
| |
| else:
| |
| sum = sum + j
| |
| print("#%d" %i, sum)
| |
| </syntaxhighlight>
| |
| <syntaxhighlight lang='python'>
| |
| T = int(input())
| |
| for tt in range(T):
| |
| n = int(input())
| |
| s = 0
| |
| for j in range(1,n+1):
| |
| if j % 2== 0:
| |
| s -= j
| |
| else:
| |
| s += j
| |
| print( f"#{tt+1}", s)
| |
| </syntaxhighlight>
| |