-
Notifications
You must be signed in to change notification settings - Fork 0
/
RRCODE.c
68 lines (56 loc) · 966 Bytes
/
RRCODE.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long int val[1004];
long long int cal(long long int N,long long int K, long long int Ans,char *opr)
{
int j;
long long int temp=val[1];
long long temp2=(K/2)*2;
K=K-temp2;
for(j=2;j<=N;j++)
{
if(strcmp(opr,"XOR")==0)
temp=temp^val[j];
else if(strcmp(opr,"OR")==0)
temp=temp | val[j];
else if(strcmp(opr,"AND")==0)
{
temp=temp & val[j];
}
}
if(strcmp(opr,"XOR")==0 && (K==1))
{
Ans=Ans^temp;
}
else if(strcmp(opr,"OR")==0)
Ans=temp | Ans;
else if(strcmp(opr,"AND")==0)
Ans=temp & Ans;
return Ans;
}
int main(void)
{
int T;
scanf("%d",&T);
while(T--)
{
int i;
long long int N,K,Ans;
scanf(" %lld%lld%lld",&N,&K,&Ans);
for(i=1;i<=N;i++)
scanf(" %lld",&val[i]);
char opr[4];
scanf(" %s",opr);
if(K==0)
{
printf("%lld\n",Ans);
}
else
{
Ans=cal(N,K,Ans,opr);
printf("%lld\n",Ans);
}
}
return 0;
}