BOJ 2441 별찍기 - 4

1 개요[ | ]

BOJ 2441 별찍기 - 4
  • 첫째 줄에는 별 N개, 둘째 줄에는 별 N-1개, ..., N번째 줄에는 별 1개를 출력해 봅니다. (오른쪽 정렬)

2 C[ | ]

#include <stdio.h>

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

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (j < 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 = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (j < 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<i ) System.out.print(" ");
                else System.out.print("*");
            }
            System.out.print("\n");
        }
    }
}

5 Perl[ | ]

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

6 PHP[ | ]

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

7 Python[ | ]

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

8 같이 보기[ | ]

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