From c371f89aea148d3ddbaf8208d2920fb14fcc8c0d Mon Sep 17 00:00:00 2001 From: Tanishq Vashisht Date: Sun, 1 Oct 2023 20:54:04 +0530 Subject: [PATCH 1/2] binary to decimal python --- python/binarytodecimal.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 python/binarytodecimal.py diff --git a/python/binarytodecimal.py b/python/binarytodecimal.py new file mode 100644 index 00000000..47bd2061 --- /dev/null +++ b/python/binarytodecimal.py @@ -0,0 +1,10 @@ +def bin_to_dec(x): + l=list(x) + l=list(map(int,l)) + bin=j=0 + for i in range(len(l)-1,-1,-1): + bin+=l[i]*2**j + j+=1 + return bin +x=input("Enter a Binary Number: ") +print(bin_to_dec(x)) \ No newline at end of file From 7c01b9eec124cbe25b5810ffb12f5de4c0fb44f6 Mon Sep 17 00:00:00 2001 From: Tanishq Vashisht Date: Sun, 1 Oct 2023 20:56:41 +0530 Subject: [PATCH 2/2] paranthesis matching stack java --- java/paranthesismatching.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 java/paranthesismatching.java diff --git a/java/paranthesismatching.java b/java/paranthesismatching.java new file mode 100644 index 00000000..b9d55e48 --- /dev/null +++ b/java/paranthesismatching.java @@ -0,0 +1,33 @@ +package com.company.Stacks; + +import java.util.Scanner; + +public class ParenthesisMatching { + + public static boolean parenthesisMatch(String exp, CharStack st){ + for (int i = 0; i < exp.length(); i++) { + if (exp.charAt(i) == '('){ + st.push("("); + } + else if (exp.charAt(i) == ')'){ + if (st.isEmpty()){ + return false; + } + st.pop(); + } + } + return st.isEmpty(); + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String exp = sc.nextLine(); + CharStack st = new CharStack(exp.length()); + if (parenthesisMatch(exp, st)){ + System.out.println("Parenthesis Match"); + } + else{ + System.out.println("Parenthesis Missing"); + } + } +} \ No newline at end of file