回复 10 楼 stop1204
很清晰,实现起来简单明了,想看看更简化的版本,不知版主能否用vector实现功能,感激不已……PS:我想楼上的哥们说的意思是定义char型数组时应该为常量,不能是变量。(编译时若为n1无法通过)
程序代码:#include <iostream>
#include <string>
#include <bitset>
int main()
{
std::string t;
std::cin >> t;
std::bitset<50> a(t), b;
std::cin >> b;
std::cout << ((~(a^b)).to_string().c_str()+50-t.size()) << std::endl;
return 0;
}
程序代码:#include <iostream>
#include <string>
#include <cassert>
int main()
{
std::string a, b;
std::cin >> a >> b;
assert( a.size() == b.size() );
for( size_t i=0; i!=a.size(); ++i )
a[i] = a[i]==b[i] ? '1' : '0';
std::cout << a << std::endl;
return 0;
}