编程日记 cha2-04 排版题
输出梯形(oj无)
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main()
{
int h;
while (cin>>h)
{
int width = h + 2*(h-1);
for (int i=0;i<h;i++)
{
for (int j = 1;j<=2*(h-i-1);j++)
cout<<' ';
for (int j = 1;j<=(h+2*i);j++)
cout<<'*';
cout<<endl;
}
}
return 0;
}
叠筐
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main()
{
int n;
char center,out;
char buffer[80][80];
int i,j,k;
char nc;
bool flag = true;
while (scanf("%d %c %c",&n,¢er,&out)!=EOF)
{
if (flag)
{
flag = false;
}
else
cout<<endl;
for (i=0,j=0;i<(n+1)/2;i++,j++)
{
if (((n+1)/2)%2 == 0 )
nc = i%2==0?out: center;
else
nc = i%2==0?center:out;
int width = n-2*i;
for (k = 0 ; k < width ; k++)
{
buffer[i][j+k] = nc;
buffer[n-1-i][j+k] = nc;
buffer[i+k][j] = nc;
buffer[i+k][n-1-j] = nc;
}
}
if (n!=1)
{
buffer[0][0] = ' ';
buffer[0][n-1]=' ';
buffer[n-1][0]=' ';
buffer[n-1][n-1]=' ';
}
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
cout<<buffer[i][j];
}
cout<<endl;
}
}
return 0;
}