Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MASAM #362

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion c/p10.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//CPP program to implement circular linked list
//CPP program to implement circular linked list (veeresh)

#include<bits/stdc++.h>
using namespace std;
Expand Down Expand Up @@ -129,6 +129,7 @@ int main(){
}
case 4:{ //exiting the menu
cout << "Exiting the menu..."<<endl;
break;
}
default: cout << "Invalid choice"<<endl; break;
}
Expand Down
2 changes: 1 addition & 1 deletion c/p11.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int isSameTree(struct TreeNode* p, struct TreeNode* q){
return 1;
}
if(p->val == q->val){
return isSameTree(p->left, q->left) || isSameTree(p->right, q->right);
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
return 0;
}
5 changes: 3 additions & 2 deletions c/p12.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//program to find the longest common subsequence (LCS) in two strings
//program to find the longest common subsequence (LCS) in two strings (veeresh)
//e.g. ABCDE and AFCZE have a common subsequence of ACE

#include <bits/stdc++.h>
Expand Down Expand Up @@ -30,10 +30,11 @@ void LCS(string a, string b, int m, int n) {
lcs[index - 1] = a[i - 1];
i--;
j--;
index--;
}
else if (dp[i - 1][j] > dp[i][j - 1]) i--;
else j--;
index--;

}

cout << "LCS: " << lcs << endl;
Expand Down
2 changes: 1 addition & 1 deletion c/p13.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main(){
printf("%d ", a[i]);
}
printf("\n");
for(i;i<m;i++){
for(int i=0;i<m;i++){
printf("%d ", b[i]);
}
}
5 changes: 3 additions & 2 deletions c/p14.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//program to convert given roman expression to it's integer form
//program to convert given roman expression to it's integer form (veeresh)

#include<stdio.h>
#include<stdlib.h>
Expand All @@ -22,7 +22,8 @@ int romanToInt(char * s){
if(a[i] < a[i+1]){
a[i+1] -= a[i];
}
num += a[i];
else
num += a[i];
}
num += a[strlen(s) - 1];
return num;
Expand Down
13 changes: 7 additions & 6 deletions c/p15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ void Upper(char *word) {
}

int Check(char *S) {
for(int k = 0, v = 0; S[k]; k++)
int v=0;
for(int k = 0; S[k]; k++)
switch(S[k]) {
case A:
case E:
case I:
case O:
case U: v++;
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':v++;
}
return v;
}
Expand Down
5 changes: 3 additions & 2 deletions c/p2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class A{
this->variable = variable;
}
int func();
int anotherFunc(A a);
~A(){
cout << "Object destroyed" << endl;
}
Expand All @@ -22,13 +23,13 @@ int A::func(){
return variable;
}

int anotherFunc(A a){
int A::anotherFunc(A a){
a.variable += 3;
return a.variable;
}

int main(){
A a;
cout << a.func() + anotherFunc(a) << endl;
cout << a.func() + a.anotherFunc(a) << endl;
return 0;
}
2 changes: 1 addition & 1 deletion c/p3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vector<int> productExceptSelf(vector<int>& nums) {
int r = 1;
for(int i=nums.size()-1;i>=0;i--){
ans[i] *= r;
r = nums[i];
r = r*nums[i];
}
return ans;
}
Expand Down
4 changes: 2 additions & 2 deletions c/p4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ string caesar(string s, int k, string direction){
string ans = "";
for(int i=0;i<s.length();i++){
if(direction == "encode"){
ans += s[i] + k;
ans += ((s[i]-'a') + k)%26 + 97;
}
else if(direction == "decode"){
ans += s[i] - k;
ans += ((s[i]-'a') - k+26)%26 + 97;
}
}
return ans;
Expand Down
5 changes: 3 additions & 2 deletions c/p5.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//program to increment and print the value of a using a pointer
//program to increment and print the value of a using a pointer (veeresh)

#include <stdio.h>

void main(){
int a=10;
int *ptr = &a;

*ptr++;
(*ptr)++; // the *ptr should be mentioned in the brackets

printf("%d", *ptr);
}
5 changes: 3 additions & 2 deletions c/p6.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//allocating memory to a pointer through a function
//allocating memory to a pointer through a function (veeresh)

#include<stdio.h>
int x;
int *fun()
{
int x = 5;
x = 5;
return &x;
}
int main()
Expand Down
3 changes: 2 additions & 1 deletion c/p7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ using namespace std;

int func(string s){
int counter=-1;
while(counter<s.length())

while(counter < int(s.length()))
counter++;
return counter;
}
Expand Down
6 changes: 3 additions & 3 deletions c/p8.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <stdio.h>

float computeAverage(float* x, size_t* N) {
float computeAverage(float* x, int* N) {
float numerator = 0.0;
float denominator = 0.0;
for (size_t i = 0; i < (size_t)N; i++) {
for (int i = 0; i < *N; i++) {
numerator += x[i];
denominator++;
}
Expand All @@ -15,7 +15,7 @@ float computeAverage(float* x, size_t* N) {
int main()
{
float x[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
size_t N = 10;
int N = 10;
printf("%.3g\n", computeAverage(x, &N));
return 0;
}
5 changes: 3 additions & 2 deletions c/p9.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
*/

#include <stdio.h>
#include <stdlib.h>

int* filterMultiples(int* arr, int N, int* NOut, int num) {
int numPrimes = 0;
*NOut = 0;
for (int i = 0; i < N; i++) {
if (arr[i] >= num && arr[i]%num == 0) {
*NOut++;
(*NOut)++;
}
}
int* multiples = malloc((*NOut)*sizeof(int));
int idx = 0;
for (int i = 0; i < *NOut; i++) {
for (int i = 0; i < N; i++) {
if (arr[i] >= num && arr[i]%num == 0) {
multiples[idx] = arr[i];
idx++;
Expand Down
9 changes: 6 additions & 3 deletions py/p10.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ def listmaker(r,g,b,list1=[]):
list1.append(b)
return list1

pixel1=listmaker(23,78,34)
pixel2=listmaker(210,56,67)
pixel3=listmaker(23,78,248)
pixel1=[]
pixel2=[]
pixel3=[]
pixel1=listmaker(23,78,34,pixel1)
pixel2=listmaker(210,56,67,pixel2)
pixel3=listmaker(23,78,248,pixel3)
r=(pixel1[0]+pixel2[0]+pixel3[0])/3
g=(pixel1[1]+pixel2[1]+pixel3[1])/3
b=(pixel1[2]+pixel2[2]+pixel3[2])/3
Expand Down
7 changes: 4 additions & 3 deletions py/p11.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Function to convert decimal to binary number

def binaryconversion(n):
print(n % 2,end = '')
if n > 1:
binaryconversion(n/2)

binaryconversion(n//2)
print(n % 2,end = '')
else:
print(n,end='')
number=int(input("Enter Number: "))
binaryconversion(number)
print()
4 changes: 2 additions & 2 deletions py/p12.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

p = len(A)
q = len(A[0])

t = len(B)
r = len(B[0])

if(q!=t):
print("Error! Matrix sizes are not compatible")
quit()
Expand Down
5 changes: 3 additions & 2 deletions py/p2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#program to print an input as the only member of an array everytime the function is called
# input- 1 -> output- [1], input- 2 -> output- [2]

def add_item(item, items=[]):
items = []
def add_item(item):
items.append(item)
return items

print(add_item(1))
items.clear()
print(add_item(2))
2 changes: 1 addition & 1 deletion py/p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#eg: [2, 4, 6, 17, 10] -> [17, 10]

def delete_starting_evens(list):
for item in list:
for i in range(len(list)):
if list[0] % 2 == 0:
list.pop(0)
else:
Expand Down
3 changes: 2 additions & 1 deletion py/p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def countSort(arr):
for i in range(k+1):
count[i] += count[i-1]
for i in range(len(arr)-1, -1, -1):
ans[count[arr[i]]] = arr[i]
print(count[arr[i]])
ans[count[arr[i]]%len(arr)-2] = arr[i]
count[arr[i]] -= 1
return ans

Expand Down
4 changes: 2 additions & 2 deletions py/p6.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def addBinary(a: str, b: str) -> str:
j -= 1
s.append(str(carry % 2))
carry //= 2

s.append(str(carry))
return ''.join(reversed(s))

print(addBinary("11", "0"))
print(addBinary("11", "00"))
2 changes: 1 addition & 1 deletion py/p8.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def iter(self):
while current:
item_val = current.data
current = current.next
yield item_val
print(item_val)

items = doubly_linked_list()
items.append_item('C#')
Expand Down