BOJ 2439 별 찍기 - 2

(BOJ 2439 별찍기 - 2에서 넘어옴)

1 개요[ | ]

BOJ 2439 별 찍기 - 2

2 C[ | ]

#include <stdio.h>

int main()
{
    int n;
    int i, j;

    scanf("%d", &n);

    for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
            if (j <= n - i)
                printf(" ");
            else
                printf("*");
        }
        printf("\n");
    }

    return 0;
}

3 C++[ | ]

#include <iostream>

using namespace std;

int main()
{
    int n;
    int i, j;

    cin >> n;

    for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
            if (j <= n - i)
                cout << " ";
            else
                cout << "*";
        }
        cout << endl;
    }

    return 0;
}

4 Java[ | ]

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                if( j>n-i ) System.out.print("*");
                else System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}

5 Perl[ | ]

$n = <>;
printf(' ' x ($n-$_) . "*" x $_ . "\n") for(1..$n);

6 PHP[ | ]

<?php
fscanf(STDIN,"%d",$n);
for($i=1; $i<=$n; $i++) echo str_repeat(' ', $n-$i) . str_repeat('*', $i) . "\n";
<?php
fscanf(STDIN,"%d",$n);
ob_start();
for($i=1; $i<=$n; $i++) {
    for($j=1; $j<=$n; $j++) {
        if( $j>$n-$i ) echo '*';
        else echo ' ';
    }
    echo "\n";
}
ob_flush();

7 Python[ | ]

n = int(input())
for i in range(1,n+1):
    print( ' '*(n-i) + '*'*i )
n = int(input())
for i in range(n):
    print( ' '*(n-i-1) + '*'*(i+1) )
n = int(input())
for i in range(1,n+1):
    print( ' ' * (n-i), end='' )
    print( '*' * i )

8 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}