LabmemNo_012LzTopic @ 2023-11-25 20:39:37
#include<stdio.h>
#include<string.h>
int main()
{
int n, i, j;
char a[1005];
string ans[6];
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
a[i] = getchar();
if (a[i] == '1')
{
ans[1] += "..X.";
ans[2] += "..X.";
ans[3] += "..X.";
ans[4] += "..X.";
ans[5] += "..X.";
}
if (a[i] == '2')
{
ans[1] += "XXX.";
ans[2] += "..X.";
ans[3] += "XXX.";
ans[4] += "X...";
ans[5] += "XXX.";
}
if (a[i] == '3')
{
ans[1] += "XXX.";
ans[2] += "..X.";
ans[3] += "XXX.";
ans[4] += "..X.";
ans[5] += "XXX.";
}
if (a[i] == '4')
{
ans[1] += "X.X.";
ans[2] += "X.X.";
ans[3] += "XXX.";
ans[4] += "..X.";
ans[5] += "..X.";
}
if (a[i] == '5')
{
ans[1] += "XXX.";
ans[2] += "X...";
ans[3] += "XXX.";
ans[4] += "..X.";
ans[5] += "XXX.";
}
if (a[i] == '6')
{
ans[1] += "XXX.";
ans[2] += "X...";
ans[3] += "XXX.";
ans[4] += "X.X.";
ans[5] += "XXX.";
}
if (a[i] == '7')
{
ans[1] += "XXX.";
ans[2] += "..X.";
ans[3] += "..X.";
ans[4] += "..X.";
ans[5] += "..X.";
}
if (a[i] == '8')
{
ans[1] += "XXX.";
ans[2] += "X.X.";
ans[3] += "XXX.";
ans[4] += "X.X.";
ans[5] += "XXX.";
}
if (a[i] == '9')
{
ans[1] += "XXX.";
ans[2] += "X.X.";
ans[3] += "XXX.";
ans[4] += "..X.";
ans[5] += "XXX.";
}
if (a[i] == '0')
{
ans[1] += "XXX.";
ans[2] += "X.X.";
ans[3] += "X.X.";
ans[4] += "X.X.";
ans[5] += "XXX.";
}
}
ans[1] -= '.';
ans[2] -= '.';
ans[3] -= '.';
ans[4] -= '.';
ans[5] -= '.';
for (j = 1; j <= 5; j++)
{
printf("%s", ans[j].c_str());
if (j != 5)printf("\n");
}
return 0;
}
by penguin_is_cool @ 2023-11-25 20:50:12
@LabmemNo_012LzTopic
首先,<string.h> 不包含string, 要用 <string>.
其次,如果用了 <string> string得改成std::string, 因为我不学c语言,所以将以上网查用法。
如果真的而要用string,那建议<iostream>或<bits/stdc++.h>(都是c++库)用string.
by LabmemNo_012LzTopic @ 2023-11-26 21:11:15
@penguin_is_cool 这个还是会报错, 不过谢谢了。 我去试试其他的写法
by penguin_is_cool @ 2023-11-26 22:02:06
@LabmemNo_012LzTopic 好的