-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstoi.cpp
More file actions
47 lines (41 loc) · 758 Bytes
/
Copy pathstoi.cpp
File metadata and controls
47 lines (41 loc) · 758 Bytes
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
#include <iostream>
#include<string>
#include<math.h>
using namespace std;
int bnToDl(string n)
{
string num = n;
int dec_value = 0;
int base = 1;
int len = num.length();
for (int i = len - 1; i >= 0; i--) {
if (num[i] == '1')
dec_value += base;
base = base * 2;
}
return dec_value;
}
int main()
{
int t,s,x,b,y,i;
cin>>t;
while(t--)
{
int max=0;
cin>>s;
char bin[s];
cin>>bin;
x = bnToDl(bin);
for(y=1;y<=s;y++)
{
b=(x/(pow(2,y)));
int max1= x xor b;
if(max1>max)
{ i=y;
max=max1;
}
}
cout<<i<<endl;
}
return 0;
}