版权声明:本人原创文章若需转载请标明出处和作者!沙 https://blog.csdn.net/weixin_44143702/article/details/88553079
1.3按位AND和按位OR
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
已知长度为n的两个位串a和b,求它们的按位AND和按位OR。
Input
多组测试数据,每组测试数据第1行输入位串长度n(0 < n <= 64),第2行输入n个以空格隔开的取值为0或1的整数表示位串a,第3行输入n个以空格隔开的取值为0或1的整数表示位串b。
Output
每组测试数据占两行,第一行输出n个以空格隔开的取值为0或1的整数表示a位串和b位串的按位AND,第2行输出n个以空格隔开的取值为0或1的整数表示a位串和b位串的按位OR。
Sample Input
5 1 0 0 1 0 0 0 0 1 1
Sample Output
0 0 0 1 0 1 0 0 1 1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
int a[65], b[65];
int main()
{
int n, i;
while(cin >> n)
{
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for(i = 1; i <= n; i++)
{
cin >> a[i];
}
for(i = 1; i <= n; i++)
{
cin >> b[i];
}
for(i = 1; i <= n; i++)
{
if(a[i] == 1 && b[i] == 1)
{
if(i == 1) printf("1");
else printf(" 1");
}
else
{
if(i == 1) printf("0");
else printf(" 0");
}
}
cout << endl;
for(i = 1; i <= n; i++)
{
if(a[i] == 0 && b[i] == 0)
{
if(i == 1) printf("0");
else printf(" 0");
}
else
{
if(i == 1) printf("1");
else printf(" 1");
}
}
cout << endl;
}
return 0;
}