Question 1115: DNA
Time limit: 1Sec Memory limit: 128MB Submit: 8923 Resolution: 3095
Title description
Xiaoqiang has been fond of life science since he was a child. He is always curious about where the flowers, grass, birds and beasts come from. Finally, Xiaoqiang went to middle school and came into contact with the sacred term--DNA. It has a double helix structure. This caused Xiaoqiang to scratch his scalp, "If only it could be drawn," Xiaoqiang shouted. Please help him now
enter
The input contains multiple sets of test data. The first integer N (N<=15), N represents the number of groups, and each group of data contains two integers a, b. a represents the number of rows of a unit of DNA string, a is an odd number and 3<=a<=39. b represents the degree of repetition (1<=b<=20).
Output
The shape of the output DNA, there is a blank line between each group of outputs.
Sample input
2 3 1 5 4Sample output
X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
Ideas:
Just find the rules and output directly.
The rule is: when j is the abscissa and k is the ordinate, output when j==k or output when j==a-1-k.
Error-prone: format problem , the first output and the following output are different from the first line. Use f to mark the first output
Implementation code:
#include<stdio.h>
int main()
{
int a,b,n,i,j,k;
scanf("%d",&n);
while(n--)
{
int f=0;
scanf("%d%d",&a,&b);
for(i=0;i<b;i++)
{
for(j=0;j<a;j++)
{
if(f==0||j!=0)
{
for(k=0;k<a;k++)
{
if(j==k||j==a-k-1)
{
printf("X");
}
else
printf(" ");
f=1;
}
printf("\n");
}
}
}
printf("\n");
}
return 0;
}
Hahahaha