codechef RRCODE - "code" editorial : http://discuss.codechef.com/questions/24632/rrcode-editorial
codechef RRCODE - "code" solution : http://ideone.com/akIeg9
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int t, n, k, ans, a[1005];
char s[5];
scanf("%d", &t);
while(t--) {
scanf("%d%d%d", &n, &k, &ans);
for(int i=0; i<n; i++) scanf("%d", &a[i]);
scanf("%s", s);
if(s[0]=='X') {
if(k%2!=0) for(int i=0; i<n; i++) ans^=a[i];
}
else if(s[0]=='A') {
if(k!=0) for(int i=0; i<n; i++) ans&=a[i];
}
else {
if(k!=0) for(int i=0; i<n; i++) ans|=a[i];
}
printf("%d\n", ans);
}
return 0;
}
note: pay attn for "k", it doesnt matter how big k is, just whether k is even or odd matters for XOR; also, dont forget the k=0 case, in which you dont need to calculate anything at all.
No comments:
Post a Comment