Luke's family
TimeLimit:
Totalsubmit:
Description
In the stars’ family, Luke only has seen his father andgrandfather. He really wants to know what his ancestors look like.We numbered Luke as the No.0 star. Luke’s father is No.1 star, andthe father of Luke’s father is No.2 star, and so on.Luke looks like:
*
Luke’s father looks like:
* * * *
* * * *
* * * * * * *
* * * * * * *
Input
There are multiple test cases.In each test case, the first line is an integer n(1<=n<=90).
Output
For each test case, first output a line “Case T:” T starts with 1.And then output what the No.n star looks like.Sample Input
0
1
2
3
Sample Output
Case 1:
*
Case 2:
* * * *
* * * *
Case 3:
* * * * * * *
* * * * * * *
Case 4:
* * * * * * * * * *
* * * * * * * * * *
Source
Luke
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespacestd;
int main(){
int n,i,j,k,s,t,T=1;
while(~scanf("%d",&n)){
printf("Case%d:\n",T++);
if(n==0)
printf("*\n");
else {
s=3*n;
for(i=0;i<n;i++){
s--;
for (j=0;j<s; j++)
printf("");
for (k=0; k<2*i+2;k++) {
if(k%2)
printf("*");
else
printf(" ");
}
printf("\n");
}
t=-1;
s=3*n+1;
for (i=0; i<n+1; i++) {
t++;
for (k=0; k<t; k++)
printf("");
for (j=i; j<s; j++){
if(j==i)
printf("*");
else
printf(" *");
}
printf("\n");
}
t=n;
s=2*n+1;
for (i=0; i<n; i++) {
t--;
s++;
for (k=0; k<t; k++) {
printf("");
}
for (j=0; j<s; j++) {
if(j==0)
printf("*");
else
printf(" *");
}
printf("\n");
}
s=2*n;
for(i=n;i>0;i--){
s++;
for (j=0;j<s-1; j++)
printf("");
for (k=2*i; k>0; k--) {
if(k%2)
printf("*");
else
printf(" ");
}
printf("\n");
}
}
}
return 0;
}