luoguCoder233 @ 2022-02-02 19:39:53
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
string ans[10];
for (int i = 0;i < 10;i ++) {
ans[i] = "";
}
int n;
cin>>n;
char a[1000000];
for (int i = 1;i <= n;i ++) {
cin>>a[i];
switch (a[i]) {
case '0':
ans[1] = ans[1] + "XXX.";
ans[2] = ans[2] + "X.X.";
ans[3] = ans[3] + "X.X.";
ans[4] = ans[4] + "X.X.";
ans[5] = ans[5] + "XXX.";
break;
case '1':
ans[1] = ans[1] + "..X.";
ans[2] = ans[2] + "..X.";
ans[3] = ans[3] + "..X.";
ans[4] = ans[4] + "..X.";
ans[5] = ans[5] + "..X.";
break;
case '2':
ans[1] = ans[1] + "XXX.";
ans[2] = ans[2] + "..X.";
ans[3] = ans[3] + "XXX.";
ans[4] = ans[4] + "X...";
ans[5] = ans[5] + "XXX.";
break;
case '3':
ans[1] = ans[1] + "XXX.";
ans[2] = ans[2] + "..X.";
ans[3] = ans[3] + "XXX.";
ans[4] = ans[4] + "..X.";
ans[5] = ans[5] + "XXX.";
break;
case '4':
ans[1] = ans[1] + "X.X.";
ans[2] = ans[2] + "X.X.";
ans[3] = ans[3] + "XXX.";
ans[4] = ans[4] + "..X.";
ans[5] = ans[5] + "..X.";
break;
case '5':
ans[1] = ans[1] + "XXX.";
ans[2] = ans[2] + "X...";
ans[3] = ans[3] + "XXX.";
ans[4] = ans[4] + "..X.";
ans[5] = ans[5] + "XXX.";
break;
case '6':
ans[1] = ans[1] + "XXX.";
ans[2] = ans[2] + "X...";
ans[3] = ans[3] + "XXX.";
ans[4] = ans[4] + "X.X.";
ans[5] = ans[5] + "XXX.";
break;
case '7':
ans[1] = ans[1] + "XXX.";
ans[2] = ans[2] + "..X.";
ans[3] = ans[3] + "..X.";
ans[4] = ans[4] + "..X.";
ans[5] = ans[5] + "..X.";
break;
case '8':
ans[1] = ans[1] + "XXX.";
ans[2] = ans[2] + "X.X.";
ans[3] = ans[3] + "XXX.";
ans[4] = ans[4] + "X.X.";
ans[5] = ans[5] + "XXX.";
break;
case '9':
ans[1] = ans[1] + "XXX.";
ans[2] = ans[2] + "X.X.";
ans[3] = ans[3] + "XXX.";
ans[4] = ans[4] + "..X.";
ans[5] = ans[5] + "XXX.";
break;
default:
break;
}
}
//output.
for (int i = 1;i <= n;i ++) {
ans[i] = ans[i].substr(0,ans[i].length() - 1);
cout<<ans[i]<<endl;
}
return 0;
}
在本地运行的时候,当第一个数字超过10时,提示Segmentation Fault,不知道是哪里出问题了。
by _Vector_ @ 2022-02-02 19:52:59
ans[]不就只存了五个空间吗?
为什么会
for (int i = 1;i <= n;i ++) {
ans[i] = ans[i].substr(0,ans[i].length() - 1);
cout<<ans[i]<<endl;
}
i从1到n呢?