"SWEA 2019 더블더블"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
;SWEA 2019 더블더블
;SWEA 2019 더블더블
* 난이도: [[SWEA D1]]
* 2를 반복해서 곱하면서 출력한다.
* 2를 반복해서 곱하면서 출력한다.
* 다른 방법으로는 [[pow()]] 함수 사용을 생각해볼 수 있다.
* 다른 방법으로는 [[pow()]] 함수 사용을 생각해볼 수 있다.

2023년 8월 18일 (금) 17:07 판

1 개요

SWEA 2019 더블더블
  • 난이도: SWEA D1
  • 2를 반복해서 곱하면서 출력한다.
  • 다른 방법으로는 pow() 함수 사용을 생각해볼 수 있다.

2 C++

#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int t = 1;
    for(int i=0; i<=n ;i++) {
        cout << t << " ";
        t *= 2;
    }
}

3 Java

import java.util.Scanner;
class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=0; i<=n; i++) {
            System.out.format("%d ", (int)Math.pow(2, i) );  
        }
    }
}

4 Python

#kcy
a = int(input())
for i in range(0, a+1):
    print(2**i,end=' ')
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}