Skip to content

Commit 2719b1a

Browse files
authored
Add files via upload
1 parent baf572c commit 2719b1a

File tree

13 files changed

+341
-0
lines changed

13 files changed

+341
-0
lines changed

Calculator.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int a, b;
7+
char operation;
8+
cout << "Enter the first no. " << endl;
9+
cin >> a;
10+
cout << "Enter the second no. " << endl;
11+
cin >> b;
12+
cout << "Enter the operation" << endl;
13+
cin >> operation;
14+
switch (operation)
15+
{
16+
case '+':
17+
cout << a << " + " << b << " = " << a + b << endl;
18+
break;
19+
20+
case '*':
21+
cout << a << " * " << b << " = " << a * b << endl;
22+
break;
23+
24+
case '-':
25+
cout << a << " - " << b << " = " << a - b << endl;
26+
break;
27+
28+
case '%':
29+
cout << a << " % " << b << " = " << a % b << endl;
30+
break;
31+
}
32+
33+
return 0;
34+
}

Exit.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int userInput;
8+
cout << "Enter a number: ";
9+
cin >> userInput;
10+
11+
if (userInput < 0)
12+
{
13+
cout << "Invalid input." << endl;
14+
exit(1);
15+
}
16+
cout << "You entered: " << userInput << endl;
17+
18+
return 0;
19+
}

Leetcode/1009.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
cout << "Enter the no. : ";
8+
cin >> n;
9+
int m = n;
10+
int mask = 0;
11+
12+
if (n == 0)
13+
{
14+
cout << "1" << endl;
15+
return 0;
16+
}
17+
18+
while (m != 0)
19+
{
20+
mask = (mask << 1) | 1;
21+
m = m >> 1;
22+
}
23+
cout << (~n & mask) << endl;
24+
25+
return 0;
26+
}

Leetcode/1207.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <vector>
4+
using namespace std;
5+
6+
bool uniqueOccurrences(vector<int> &arr)
7+
{
8+
vector<int> counter;
9+
10+
sort(arr.begin(), arr.end());
11+
12+
int count = 1;
13+
for (int i = 1; i < arr.size(); i++)
14+
{
15+
if (arr[i] == arr[i - 1])
16+
{
17+
count += 1;
18+
}
19+
else
20+
{
21+
counter.push_back(count);
22+
count = 1;
23+
}
24+
}
25+
counter.push_back(count);
26+
27+
for (int i = 1; i < counter.size(); i++)
28+
{
29+
if (counter[i] == counter[i - 1])
30+
{
31+
return false;
32+
}
33+
}
34+
return true;
35+
}
36+
37+
int main()
38+
{
39+
vector<int> arr = {1, 2, 2, 1, 1, 3};
40+
41+
bool result = uniqueOccurrences(arr);
42+
43+
if (result)
44+
{
45+
cout << "Occurrences are unique." << endl;
46+
}
47+
else
48+
{
49+
cout << "Occurrences are not unique." << endl;
50+
}
51+
52+
return 0;
53+
}

Leetcode/1281

16.2 KB
Binary file not shown.

Leetcode/1281.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
cin >> n;
8+
int sum = 0;
9+
int product = 1;
10+
11+
while (n != 0)
12+
{
13+
sum += (n % 10);
14+
product *= (n % 10);
15+
n = n / 10;
16+
}
17+
18+
int ans = product - sum;
19+
cout << ans << endl;
20+
21+
return 0;
22+
}

Leetcode/191

16.2 KB
Binary file not shown.

Leetcode/191.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
cin >> n;
8+
int count = 0;
9+
10+
while (n != 0)
11+
{
12+
if (n % 10 == 1)
13+
{
14+
count += 1;
15+
}
16+
n = n / 10;
17+
}
18+
19+
cout << count << endl;
20+
21+
return 0;
22+
}

Leetcode/231.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
cin >> n;
8+
int count = 0;
9+
10+
if (n <= 0)
11+
{
12+
cout << "0" << endl;
13+
return 0;
14+
}
15+
16+
cout << ((n & (n - 1)) == 0);
17+
18+
return 0;
19+
}

Leetcode/442.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int nums[] = {4, 3, 2, 7, 8, 2, 3, 1};
8+
int numsSize = sizeof(nums) / sizeof(nums[0]);
9+
10+
sort(nums, nums + numsSize);
11+
12+
int ans[100];
13+
int ansIndex = 0;
14+
15+
for (int i = 1; i < numsSize; i++)
16+
{
17+
if (nums[i] == nums[i - 1])
18+
{
19+
ans[ansIndex++] = nums[i];
20+
}
21+
}
22+
23+
cout << "Duplicates: ";
24+
for (int i = 0; i < ansIndex; i++)
25+
{
26+
cout << ans[i] << " ";
27+
}
28+
cout << endl;
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)