Problem description
打印#组成的三角形图形。
Input
输入数据有若干行。每一行有一个非负整数n(0<=n<=20)对应一种情形。
Output
对于每一种情形,先输出“Case #:”(#为序号,从1起),换行;然后输出结果(参见输出样例)。
Sample Input
2
7
Sample Output
Case 1:
#
###
Case 2:
#
###
#####
#######
#########
###########
#############
打印#组成的三角形图形。
Input
输入数据有若干行。每一行有一个非负整数n(0<=n<=20)对应一种情形。
Output
对于每一种情形,先输出“Case #:”(#为序号,从1起),换行;然后输出结果(参见输出样例)。
Sample Input
2
7
Sample Output
Case 1:
#
###
Case 2:
#
###
#####
#######
#########
###########
#############
#include<iostream>
using namespace std;
void print(int n)
{
for(int i = 1; i <= n; i ++)
{ for(int j = 1; j <= n*2 - 1;j++)
{
if(j > n - i && j < n + i)
cout << "#" ;
if(j <= n-i)
cout << " ";
}
cout << endl;
}
}
int main()
{
int n,i=0;
while(cin >> n)
{
i ++;
cout << "Case " << i << ":\n";
print(n);
}
}