您的位置:首页 > 其它

九度考研机试教程 15-题目1432:叠筐 排版题

2015-10-21 13:23 387 查看
////题目1432:叠筐

//#include<iostream>

//using namespace std;

//int main(){

// int n;

// char X,Y;

// while(cin>>n){

// cin>>X>>Y;

// char pattern[100][100];

// for(int i=0;i<n;i++) pattern[0][i]=Y;

// for(int i=1;i<n/2+1;i++){

// for(int j=0;j<n;j++){

// pattern[i][j]=pattern[i-1][j];

// }

// for(int j=i;j<n-i;j++){

// if(i%2!=0){

// pattern[i][j]=X;

// }

// else pattern[i][j]=Y;

// }

// }

// pattern[0][0]=' ';pattern[0][n-1]=' ';

// for(int i=0;i<n/2+1;i++){

// for(int j=0;j<n;j++){

// cout<<pattern[i][j];

// }

// cout<<endl;

// }

// for(int i=n/2-1;i>=0;i--){

// for(int j=0;j<n;j++){

// cout<<pattern[i][j];

// }

// cout<<endl;

// }

// cout<<endl;

// }

//}

#include<iostream>

using namespace std;

char map[82][82];

void draw(char c[82][82], char item, int s, int e)

{

for (int i=s; i<e; i++)

{

for (int j=s; j<e; j++)

{

c[i][j] = item;

}

}

}

int main()

{

bool first = true;

int n, i, j;

char a,b;

char items[2];

while (cin >> n)

{

if (first)

{

first = false;

}

else

{

cout << endl;

}

cin >> a >> b;

if (((n-1)/2)%2)//判断外层需要用哪个字符填充

{

items[1] = a;

items[0] = b;

}

else

{

items[0] = a;

items[1] = b;

}

for (i=0; i<n; i++)

{

draw(map, items[i%2], i, n-i);

}

if (n>1)

{

map[0][0] = ' ';

map[0][n-1] = ' ';

map[n-1][0] = ' ';

map[n-1][n-1] = ' ';

}

for (i=0; i<n; i++)

{

for (j=0; j<n; j++)

{

cout << map[i][j];

}

cout << endl;

}

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: