-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day +29.c
76 lines (63 loc) · 1.56 KB
/
Day +29.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
69
70
71
72
73
74
75
76
//Bitwise AND
/* program to complete the bitwiseAnd function and
find the values of A and B */
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* readline();
char* ltrim(char*);
char* rtrim(char*);
char** split_string(char*);
int parse_int(char*);
void calculate_the_maximum(int n, int k) {
//Write your code here.
int i,j;
int max=0;
int h=0;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
int v=i&j;
if(v>=k)
break;
if(max<v)
max=v;
}
}
printf("%d\n",max);
}
int main()
{
char* t_endptr;
char* t_str = readline();
int t = strtol(t_str, &t_endptr, 10);
if (t_endptr == t_str || *t_endptr != '\0') { exit(EXIT_FAILURE); }
for (int t_itr = 0; t_itr < t; t_itr++) {
char** nk = split_string(readline());
char* n_endptr;
char* n_str = nk[0];
if (t_endptr == t_str || *t_endptr != '\0') { exit(EXIT_FAILURE); }
for (int t_itr = 0; t_itr < t; t_itr++) {
char** nk = split_string(readline());
char* n_endptr;
char* n_str = nk[0];
int n = strtol(n_str, &n_endptr, 10);
if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); }
char* k_endptr;
char* k_str = nk[1];
int k = strtol(k_str, &k_endptr, 10);
calculate_the_maximum(n,k);
if (k_endptr == k_str || *k_endptr != '\0') {
exit(EXIT_FAILURE);
}
}
return 0;
}