poj 3173 Parkside's Triangle
Parkside's Triangle
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6482 | Accepted: 3918 |
Description
Bessie taught the cows to make Parkside's Triangle. It is generated from two numbers: the size and the seed. The size N (1 <= N <= 20) determines how many rows are in the triangle and the seed S (1 <= S <= 9) determines the first number in the triangle. Here are two examples:
Analyze the above examples, discover the rule, and write a program that will generate Parkside's Triangle given any size N (1 <= N <= 20) and any seed S (1 <= S <= 9).
N=5, S=3 N=6, S=1The first line of any triangle has no blanks at its front.
3 4 6 9 4 1 2 4 7 2 7
5 7 1 5 3 5 8 3 8
8 2 6 6 9 4 9
3 7 1 5 1
8 6 2
3
Analyze the above examples, discover the rule, and write a program that will generate Parkside's Triangle given any size N (1 <= N <= 20) and any seed S (1 <= S <= 9).
Input
Line 1: Two space-separated integers: N and S
Output
Lines 1..N: Parkside's Triangle as above; no trailing blanks on any line.
Sample Input
5 3
Sample Output
3 4 6 9 4
5 7 1 5
8 2 6
3 7
8
#include<iostream>
using namespace std;
int main()
{
int tri[20][20]={0};
int i,j,m;
int n,s;
cin>>n>>s;
m=s;
for(i=0;i<n;i++)
{
j=0;
while(j<=i)
{
tri[j][i]=m;
if(m<=9)
m++;
if(m==10)
m=1;
j++;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(tri[i][j]>0)
{
if(j<n-1)
cout<<tri[i][j]<<"";
if(j==n-1)
cout<<tri[i][j];
}
else
cout<<"";
}
cout<<endl;
}
return 0;
}
浙公网安备 33010602011771号