BlueBook
p183ex6 - Pascal's Triangle
Given an integer N, output the first N rows of Pascal's triangle.Input
A single integer N (1 ≤ N ≤ 20).Output
The first N rows of Pascal's triangle, in order from top to bottom. Each row should be printed in a separate line, and the entries in each row should be printed from left to right with exactly one space between each pair of horizontally adjacent entries.Sample Input
3
Sample Output
1 1 1 1 2 1
All Submissions
Best Solutions
Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 25, 2008
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
Anyway: so long as you're not doing anything that's clearly cheating, e.g. copying code or hardcoding the output, you can do more or less whatever you want.
If you hardcode output based on the test input because you have prior knowledge of the test cases, then yes, that's cheating.
If a problem has only a possible inputs and you precompute the answers to all of them, so your program is effectively cin >> input; cout << answer[input];, then that's a bit borderline. I mean, if your precomputation program takes 2 days and 3 GB of memory to run, then you basically just ignored the time and memory limits, so I would personally consider it cheating.
If, however, a problem has only five possible inputs, and solving each instance takes only a few seconds of human thought (so microseconds of CPU time), then that's completely legitimate.
Basically, if it seems like it's cheating, it's probably cheating. If it doesn't, then it's probably fine.
var
a:array [1..s] of integer?
a:array [1..10,1..20] of integer;
a[8,19]=5;
A 2D array is like an array of arrays. If a 1D array is like a line of variables, think of a 2D array as a grid.