Skip to content

Commit 6a37ec6

Browse files
Merge pull request #16 from mairohanhoon/main
ADDED DAILY PROBLEM OF DAY: 10 Oct 2023
2 parents 2d0125a + ba29f06 commit 6a37ec6

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int lengthOfNumber(int k)
5+
{
6+
if(k%2 == 0 || k%5 == 0){
7+
return -1;
8+
}
9+
long long int n = 0;
10+
for(int i=1; i<=k; i++){
11+
int n = ((n*10)+1) % k;
12+
if(n==0){
13+
return i;
14+
}
15+
}
16+
return -1;
17+
}
18+
19+
int main(){
20+
21+
int k = 1;
22+
cout << lengthOfNumber(k);
23+
24+
return 0;
25+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
int swapAdjacentBits(int n)
4+
{
5+
// Write your code here
6+
if(n == 0){
7+
return n;
8+
}
9+
vector<int> bitt;
10+
while(n!=0){
11+
bitt.push_back(n%2);
12+
n/=2;
13+
}
14+
if(bitt.size()%2 != 0){
15+
bitt.push_back(0);
16+
}
17+
reverse(bitt.begin(), bitt.end());
18+
int num = 0;
19+
int po = 0;
20+
for(int i=0; i<bitt.size()-1; i++){
21+
swap(bitt[i], bitt[i+1]);
22+
i++;
23+
}
24+
for(int i=bitt.size()-1; i>=0; i--){
25+
if(bitt[i] == 1){
26+
num += pow(2, po);
27+
}
28+
po++;
29+
}
30+
return num;
31+
}
32+
33+
int main(){
34+
35+
int n = 9;
36+
cout << swapAdjacentBits(n) << endl;
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)