做一个数学题目很简单,按照公式来计算就可以了,空间想象画图就饿可以表示,但是想要一个显示屏来出现想要的图片,需要一个代码。
这次的题目如下:
不得不说,我真的觉得这是一个枚举的题目。对数组里面的数字进行判断,每一个每一个数字对应一个结果。
定义一个char类型的数组,其大小为char b【5】【4】,然后对应一的时候将里面的每一个元素更新为想要的那个,最后在进行输出,代码如下:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int a[100];
int n;
cin >> n;
string s, ans[5];
for (int i = 0; i < n; i++)cin >> a[n];
for (int i = 0; i < n; i++) {
if (a[i] == 0) {
ans[0] = "XXX "; ans[1] = "X.X "; ans[2] = "X.X "; ans[3] = "X.X "; ans[4] = "XXX ";
}
if (a[i] == 1) {
ans[0] = "..X "; ans[1] = "..X "; ans[2] = "..X "; ans[3] = "..X "; ans[4] = "..X ";
}
if (a[i] == 2) {
ans[0] = "XXX "; ans[1] = "X.. "; ans[2] = "XXX "; ans[3] = "..X "; ans[4] = "XXX ";
}
if (a[i] == 3) {
ans[0] = "XXX "; ans[1] = "..X "; ans[2] = "XXX "; ans[3] = "..X "; ans[4] = "XXX ";
}
if (a[i] == 4) {
ans[0] = "..X "; ans[1] = "..X "; ans[2] = "XXX "; ans[3] = "X.X "; ans[4] = "X.X ";
}
if (a[i] == 5) {
ans[0] = "XXX "; ans[1] = "..X "; ans[2] = "XXX "; ans[3] = "X.. "; ans[4] = "XXX ";
}
if (a[i] == 6) {
ans[0] = "XXX "; ans[1] = "X.X "; ans[2] = "XXX "; ans[3] = "X.. "; ans[4] = "XXX ";
}
if (a[i] == 7) {
ans[0] = "..X "; ans[1] = "..X "; ans[2] = "..X "; ans[3] = "..X "; ans[4] = "XXX ";
}
if (a[i] == 8) {
ans[0] = "XXX "; ans[1] = "X.X "; ans[2] = "XXX "; ans[3] = "X.X "; ans[4] = "XXX ";
}
if (a[i] == 9) {
ans[0] = "..X "; ans[1] = "..X "; ans[2] = "XXX "; ans[3] = "X.X "; ans[4] = "XXX ";
}
cout << ans[4] << endl << ans[3] << endl << ans[2] << endl << ans[1] << endl << ans[0] << endl;
}
return 0;
}
确实简单粗暴了一点,但是我认为应该满足了题目的要求,但是在测评的时候,还是爆了,五个点都爆了。这个思路是最简单的,条件什么的也是清晰明了。然后我去看了看题解,发现许多大佬和我一样,都是使用了类似的方法。
代码如下:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
char W[10][5][3]=//W[i][j][k]表示第i个数字的第j行的第k列,(手打累死了)
{
{//0
'X','X','X',
'X','.','X',
'X','.','X',
'X','.','X',
'X','X','X',
},
{//1
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
},
{//2
'X','X','X',
'.','.','X',
'X','X','X',
'X','.','.',
'X','X','X',
},
{//3
'X','X','X',
'.','.','X',
'X','X','X',
'.','.','X',
'X','X','X',
},
{//4
'X','.','X',
'X','.','X',
'X','X','X',
'.','.','X',
'.','.','X',
},
{//5
'X','X','X',
'X','.','.',
'X','X','X',
'.','.','X',
'X','X','X',
},
{//6
'X','X','X',
'X','.','.',
'X','X','X',
'X','.','X',
'X','X','X',
},
{//7
'X','X','X',
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
},
{//8
'X','X','X',
'X','.','X',
'X','X','X',
'X','.','X',
'X','X','X',
},
{//9
'X','X','X',
'X','.','X',
'X','X','X',
'.','.','X',
'X','X','X',
}
};
int n;
char s[110];
int main(){
cin>>n;//输入n
for(int i=0;i<n;i++){
cin>>s[i];//输入要打印的字符
}
for(int i=0;i<5;i++){//枚举每一行
for(int j=0;j<n;j++){//枚举每一个数字
for(int k=0;k<3;k++){//枚举每个数字的列
cout<<W[s[j]-'0'][i][k];//输出,因为s[j]为字符,所以要减去'0'
}
if(j!=n-1) cout<<'.';//如果最后一列,就不需要打印'.'
}
cout<<endl;//换行
}
return 0;
}
虽然和我的有些不同,但是,这个代码又可以运行,有点想不通。