过了样例,说明没什么大问题,但 WA。求大佬调试,谢谢!
//程序算法:位运算
//C++14(GCC 9) O2
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=110;
string disk[N][N];
int d,s,b;
char op;
void print_disk()
{
for(int i=1;i<=b;i++)
{
for(int j=1;j<=d;j++)
cout<<disk[i][j]<<' ';
cout<<endl;
}
}
void print_0x(string s)
{
int x=0;
for(int i=0;i<s.size();i++)
x=x*2+s[i]-'0';
if(x==0)
{
cout<<"0"<<endl;
return;
}
//cout<<x<<endl;
string ans="";
while(x)
{
int r=x%16;
//cout<<r<<endl;
char c;
if(r<10)c=r+'0';
else c='A'+r-10;
ans=c+ans;
x/=16;
}
cout<<ans<<endl;
}
bool is_valid(string& ans)
{
for(int i=1;i<=b;i++) //判断第b个数据块是否合法
{
for(int j=1;j<=s;j++) //使用时下标需减1
{
int cnt=0,tmp=0,pos=-1;
for(int k=1;k<=d;k++)
{
char c=disk[i][k][j-1];
//cout<<disk[i][k]<<' '<<c<<endl;
if(c=='x')
{
if(cnt>=2)return false;
else pos=k;
}
else tmp^=(c-'0');
}
//cout<<pos<<endl;
if(pos!=-1)
{
int num;
if(op=='E')num=tmp^0;
else num=tmp^1;
disk[i][pos][j-1]=num+'0';
}
else
{
if(op=='E'&&tmp==1)return false;
if(op=='O'&&tmp==0)return false;
}
}
}
//print_disk();
string str="";
for(int i=1;i<=b;i++)
for(int j=1;j<=d;j++)
{
if((i%d==0&&j==d)||i%d==j)continue;
str+=disk[i][j];
}
for(int i=1;i<=str.size()%4;i++)
str+='0';
ans=str;
//cout<<ans<<endl;
return true;
}
void fast_read()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
signed main()
{
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
for(int kase=1;cin>>d&&d;kase++)
{
cin>>s>>b>>op;
//输入disk
for(int i=1;i<=d*b;i++)
{
string str;
char ch;
for(int j=1;j<=s;j++)cin>>ch,str+=ch;
//cout<<d<<' '<<s<<' '<<b<<endl;
if(i%b==0)disk[b][i/b]=str;
else disk[i%b][i/b+1]=str;
}
// print_disk();
// cout<<"---------------------------------------------"<<endl;
string ans="";
if(is_valid(ans))
printf("Disk set %lld is valid, contents are: ",kase),print_0x(ans);
else printf("Disk set %lld is invalid.",kase),cout<<endl;
}
return 0;
}