Algoogle

Algorithm for Programming Contest

PKU 3173 Parkside’s Triangle

Category: PKU Tag: implementation

Parkside’s Triangle

問題概要


解法


順番に表に埋めていけばよい

コード


(3173.cpp) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

int N, S;
int table[21][21];

int main(){
    cin >> N >> S;
    for(int i = 0; i < N; i++)
        for(int j = 0; j <= i; j++){
            table[j][i] = S++;
            if(S == 10) S = 1;
        }
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++){
            if(table[i][j]) cout << table[i][j];
            else cout << ' ';
            cout << (j==N-1? '\n': ' ');
        }
}

Comments