Xiang da OJ Address: http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1086
Diamond Time limit: +Ms | Memory Limit:65536Kb
Description
Xiao Ming is now a student of the 10-degree computer Department of Xiangtan University. His C language is still available, but today the teacher assigned a class after the homework problem but he was baffled. The title means to print a diamond and the diamond diagonal in a n*n (N-odd) diamond Square with the character ' * ', which is filled with the character ' _ ' In addition to the ' * ' character in the diamond. Figure I and figure two are the patterns of n=7 and n=9 respectively. Xiao Ming is a competitive person, he does not want to ask other students in the class, so he secretly run to help you, I hope you can help him.
  &NBS P
Figure A figure II
Input
The input contains multiple samples, each of which is an odd n (5 <= N < 50). When n is 0, the input ends, and this 0 does not need to be processed.
Output
for each sample, the diamond pattern is printed with the character ' * ' in the square of the n*n. (Note: The remainder of the diamond is filled with the ' _ ' character except for the character ' * ')
Sample Input
5
7
0
Sample Output
__*__
_***_
*****
_***_
__*__
___*___
__***__
_*_*_*_
*******
_*_*_*_
__***__
___*___
#include <stdio.h> #include <iostream>using namespace std;/* used to print diamond */void ha (int n) {int i,j,b; int index=1; int temp; int flag=1; Header for (i=1;i<=n;i++) {if (i!=n/2+1) {printf ("_"); }else{printf ("*"); }} printf ("\ n"); For (i=1;i<= (n-3)/2;i++) {temp= (n-3-(i-1) *)/2; for (j=1;j<=temp;j++) {printf ("_"); } printf ("*"); for (b=1;b<i;b++) {printf ("_"); } printf ("*"); for (b=1;b<i;b++) {printf ("_"); } printf ("*"); for (j=1;j<=temp;j++) {printf ("_"); } printf ("\ n"); } for (i=1;i<=n;i++) {printf ("*"); } printf ("\ n"); for (i= (n-3)/2;i>=1;i--) {temp= (n-3-(i-1) *)/2; for (j=1;j<=temp;j++) {printf ("_"); } printf ("*"); for (b=1;b<i;b++) {printf ("_"); } printf ("*"); for (b=1;b<i;b++) {printf ("_"); } printf ("*"); for (j=1;j<=temp;j++) {printf ("_"); } printf ("\ n"); }//tail for (i=1;i<=n;i++) {if (i!=n/2+1) {printf ("_"); }else{printf ("*"); }} printf ("\ n");} int main () {int n; while (scanf ("%d", &n) &&n!=0) {ha (n); }}
acm--Xiang da oj 1086--diamond--water