#include<iostream>
using namespace std;
int main(void)
{
char a[50],b[50],ch;
int i = 0,j = 0;
cin.get(ch);
while(ch != '\n')
{
a[i] = ch;
i++;
cin.get(ch);
}
// getchar();
cin.get(ch);
while(ch != '\n')
{
b[j] = ch;
j++;
cin.get(ch);
}
// getchar();
for(int n = 0;n < i;n++)
{
if(a[n] == '1' && b[n] == '1')
{
cout << '1';
}
else if(a[n] == '1' && b[n] == '0')
{
cout << '0';
}
else if(a[n] == '0' && b[n] == '1')
{
cout << '0';
}
else
{
cout << '1';
}
}
return 0;
}
样例输入没有错误,只是一直说是段错误,求大神看看
It should be enough to change a[50] and b[50] to a[51] and b[51]
In fact, if you use XOR judgment, you don’t need an array. You need to XOR first and then negate it.