问题 F : 8
题目描述
人们都喜欢8这个数字,手机号希望全是8,车牌号也希望全是8.在这个无发不在的世界,8俨然成为了人们发财的数字。为了以后我们的前途,大家来画8吧,谁画的标准,好看,谁的前途就越好。
输入格式
多组测试数据。每组中有一个字符c(大写字母或者小写字母)和一个整数n,字符表示画笔,整数表示高度。,(5<=n<=20).
输出
画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形.
样例输入
A 7
B 8
样例输出
AA
AA AA
AA AA
AA
AA AA
AA AA
AA
BBB
BB BB
BB BB
BBB
BB BB
BB BB
BB BB
BBB
这个代码很清晰的可以看懂~~
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,t,w,n1,n2,hw,i;
char c;
while(cin>>c>>n)
{
w=n/6+1;
t=n-3;
n1=t/2;
if((t%2)==0)
n2=t/2;
else if((t%2)==1)
n2=t/2+1;
hw=n2;
cout<<setfill(' ')<<setw(w)<<' '<<setfill(c)<<setw(hw)<<c<<endl;
for(i=0;i<n1;i++)
cout<<setfill(c)<<setw(w)<<c<<setfill(' ')<<setw(hw)<<' '
<<setfill(c)<<setw(w)<<c<<endl;
cout<<setfill(' ')<<setw(w)<<' '<<setfill(c)<<setw(hw)<<c<<endl;
for(i=0;i<n2;i++)
cout<<setfill(c)<<setw(w)<<c<<setfill(' ')<<setw(hw)<<' '
<<setfill(c)<<setw(w)<<c<<endl;
cout<<setfill(' ')<<setw(w)<<' '<<setfill(c)<<setw(hw)<<c<<endl;
}
return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,t,w,n1,n2,hw,i;
char c;
while(cin>>c>>n)
{
w=n/6+1;
t=n-3;
n1=t/2;
if((t%2)==0)
n2=t/2;
else if((t%2)==1)
n2=t/2+1;
hw=n2;
cout<<setfill(' ')<<setw(w)<<' '<<setfill(c)<<setw(hw)<<c<<endl;
for(i=0;i<n1;i++)
cout<<setfill(c)<<setw(w)<<c<<setfill(' ')<<setw(hw)<<' '
<<setfill(c)<<setw(w)<<c<<endl;
cout<<setfill(' ')<<setw(w)<<' '<<setfill(c)<<setw(hw)<<c<<endl;
for(i=0;i<n2;i++)
cout<<setfill(c)<<setw(w)<<c<<setfill(' ')<<setw(hw)<<' '
<<setfill(c)<<setw(w)<<c<<endl;
cout<<setfill(' ')<<setw(w)<<' '<<setfill(c)<<setw(hw)<<c<<endl;
}
return 0;
}

本文介绍了一种使用C++编程语言实现绘制数字8的算法。该算法通过输入字符和高度参数,根据特定规则输出由指定字符组成的数字8图案。文章提供了一个清晰易懂的代码示例,并详细解释了输出图案的格式。
2444

被折叠的 条评论
为什么被折叠?



