Digital diamond pattern
This question, in fact, tested the technique you use the For loop.
topic
Digital diamond pattern
Time Limit:1000MS Memory Limit:65536K
Total Submit:24 Accepted:16
Description
N of the input values, output digital diamond pattern of a n-layer.
Input
Only one line and only a positive integer: n (1 <= n <= 9)
Output
A number of digits n-layer diamond pattern, "1" on the first line 40 wherein the first layer.
Sample Input
5
Sample Output
1
121
12321
1234321
123454321
1234321
12321
121
1
Accepted Code
#include <iostream>
#include <iomanip>
using namespace std;
long long n,k;
int main()
{
cin>>n;
for(int i=1;i<=2*n-1;i++){
if(i<=n) k=i;
else k=2*n-i;
cout<<setw(41-k)<<1;
for(int j=2;j<=2*k-1;j++){
if(j<=k) cout<<j;
else cout<<2*k-j;
}
cout<<endl;
}
return 0;
}
I'm concerned about, give you more explanations -