//2017-02-08 #include <stdio.h>#include <vector>using namespace std;void init(vector<vector<char> >&array,int size){ for (int i=0;i<size;i++) array[i].resize(size); for (int i=0;i<size;i++) { for (int j=0;j<size;j++) { array[i][j]='.'; } }}void draw(vector<vector<char> >&array,int mid,int last){ //left-top int i=2,j=2; while(i<=mid){ array[i][j]=array[i-1][j]=array[i][j-1]='$'; int k=i-2; int m=j; while(m<=mid){ array[k][m]='$'; m++; } k=i; m=j-2; while(k<=mid){ array[k][m]='$'; k++; } i+=2; j+=2; } //right-top for (j=0;j<=mid;j++) for (i=mid+1;i<=last;i++) array[i][j]=array[last-i][j]; //left-bottom for (j=mid+1;j<=last;j++) for (i=0;i<=mid;i++) array[i][j]=array[i][last-j]; //right-bottom for (j=mid+1;j<=last;j++) for (i=mid+1;i<=last;i++) array[i][j]=array[last-i][j]; } void PRint(vector<vector<char> >array,int size){ for (int i=0;i<size;i++) { for (int j=0;j<size;j++) { printf("%c",array[i][j]); } printf("/n"); }}int main(){ int n; scanf("%d",&n); int mid=2*n+2; int last=mid*2; vector<vector<char> >array(last+1); init(array,last+1); draw(array,mid,last); print(array,last+1); return 0 ;}
新闻热点
疑难解答