AC是AC了,这个题AC不难,但是官方udebug里提供了一个超大规模的样例,我的结果输出了一半然后后一半都乱码了,是爆栈了还是咋了,搞不懂,求解啊。(下方udebug链接里第二个测试样例)
代码
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string sa[7];
char cc[6] = {'A','B','C','D','E','F'};
string ck(int b);
int d = 0,s = 0,n = 0,c = 0;
int main()
{
while(cin>>d && d && cin>>s && cin>>n)
{
int y = 0;
string sf;
cin>>sf;
y = sf[0]=='E'?0:1;
for(int i = 0;i<d;++i)
cin>>sa[i];
string sd,sv;
sd = ck(y);
if(sd != "")
{
while(sd.size()%4)
sd.append(1,'0');
cout<<"Disk set "<<++c<<" is valid, contents are: ";
for(int i = sd.size()-1;i>=0;i-=4){
int u = 1;
int t = 0;
for(int j = i;j>i-4 && j>=0;--j){
t+=u*(sd[j]-'0');
u=u*2;
}
if(t<10) sv.append(1,t+48);
else sv.append(1,cc[t-10]);
}
for(int i = sv.size()-1;i>=0;--i)
cout<<sv[i];
cout<<endl;
}
else cout<<"Disk set "<<++c<<" is invalid."<<endl;
}
}
string ck(int b)
{
int p = 0,q = 0;
string ss;
for(int k = 0;k<=n*s-1-(s-1);k+=s)
{
for(int i = 0;i<d;++i)
{
for(int j = k;j<k+s;++j)
{
if(sa[i][j] == 'x')
{
int cnt = 0;
for(int pp = 0;pp<d;++pp)
{
if(pp != i)
{
if(sa[pp][j] == 'x') return "";
if(sa[pp][j] == '1') ++cnt;
}
}
sa[i][j] = cnt%2==b?'0':'1';
}
if((p-i)%d)
ss.append(1,sa[i][j]);
}
}
++p;
}
for(int j = 0;j<s*n;++j){
q = 0;
for(int i = 0;i<d;++i)
q+=sa[i][j]-'0';
if(q%2 != b) return "";
}
return ss;
}