Stacked baskets
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 12017 accepted submission (s): 3074
When the Problem description is required, the baskets with different sizes are stacked so that the colors of the baskets are staggered from the top down. This job is now going to be done by the computer. It depends on you.
The input is a three-character pair, which is, the size of the outer basket is n (n is an odd integer that satisfies 0 <n <80), the central color character, and the color character of the outer basket, both are ASCII visible characters;
Output outputs a basket pattern stacked together. The central color and the color characters of the outer basket are staggered from the inner layer. When multiple baskets are stacked, the corners of the outermost basket are always polished. The stacked baskets and stacked baskets should be separated by one line.
Sample Input
11 B A5 @ W
Sample output
AAAAAAAAA ABBBBBBBBBAABAAAAAAABAABABBBBBABAABABAAABABAABABABABABAABABAAABABAABABBBBBABAABAAAAAAABAABBBBBBBBBA AAAAAAAAA @@@ @[email protected]@[email protected]@@[email protected] @@@
#include<iostream>#include<cstring>using namespace std;int main(){int n;char c1,c2,k=0;while(cin>>n){cin>>c1>>c2;int i,j,m,p,q;char str[81][81];memset(str,0,sizeof(str));p=0;q=n-1;m=(n-1)/2;if(k++) cout<<endl;if(n==1)cout<<c1<<endl;else{while(m<=q){if((q-p+1)%4==3){for(i=p;i<=q;i++)for(j=p;j<=q;j++)str[i][j]=c2;p++;q--;}else{for(i=p;i<=q;i++)for(j=p;j<=q;j++)str[i][j]=c1;p++;q--;}}str[0][0]=str[n-1][0]=str[0][n-1]=str[n-1][n-1]=' ';for(i=0;i<n;i++)cout<<str[i]<<endl;}}return 0;}
Hduj 2074 stacked basket Simulation