{"id":"a72a8645-3959-44f0-aed9-c648398a981d","name":"Basic Calculator Ii","description":"1. Given a string s which represents an expression, evaluate this expression and return its value. \r\n2. while dividing (/) numbers discard the decimal part.Example 3/2 should be 1 insteed of 1.5","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= s.length &lt;= 3 * 10^5\r\n2. s consists of digits and operators ('+', '-', '*', '/') separated by some number of spaces.\r\n3. All the integers in the expression are non-negative integers.\r\n","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <stack>\nusing namespace std;\n \n int calculate(string s) {\n // Write your code here\n }\n\nint main()\n{\n string s;\n getline(cin,s);\n cout << calculate(s) << endl;\n \n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int calculate(String s) {\r\n\r\n Stack<Integer> st = new Stack<>();\r\n\r\n return 0;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int result = calculate(read.readLine());\r\n System.out.println(result);\r\n\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3+3/2*3-2","sampleOutput":"4\r\n","questionVideo":"https://www.youtube.com/embed/gmy6L9vHTbo","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"cb27d06d-613c-4305-a4b2-4d7f195a68a8","name":"Basic Calculator Ii","slug":"basic-calculator-ii","type":1}],"next":{"id":"be2bd28e-f10a-42c6-a368-cd78fba49a7f","name":"Basic Calculator Ii MCQ","type":0,"slug":"basic-calculator-ii-mcq"},"prev":{"id":"cde85b0f-3a4a-4d24-88f7-a551a25714bc","name":"Basic Calculator","type":3,"slug":"basic-calculator"}}}

Basic Calculator Ii

1. Given a string s which represents an expression, evaluate this expression and return its value. 2. while dividing (/) numbers discard the decimal part.Example 3/2 should be 1 insteed of 1.5

{"id":"a72a8645-3959-44f0-aed9-c648398a981d","name":"Basic Calculator Ii","description":"1. Given a string s which represents an expression, evaluate this expression and return its value. \r\n2. while dividing (/) numbers discard the decimal part.Example 3/2 should be 1 insteed of 1.5","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= s.length &lt;= 3 * 10^5\r\n2. s consists of digits and operators ('+', '-', '*', '/') separated by some number of spaces.\r\n3. All the integers in the expression are non-negative integers.\r\n","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <stack>\nusing namespace std;\n \n int calculate(string s) {\n // Write your code here\n }\n\nint main()\n{\n string s;\n getline(cin,s);\n cout << calculate(s) << endl;\n \n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int calculate(String s) {\r\n\r\n Stack<Integer> st = new Stack<>();\r\n\r\n return 0;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int result = calculate(read.readLine());\r\n System.out.println(result);\r\n\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3+3/2*3-2","sampleOutput":"4\r\n","questionVideo":"https://www.youtube.com/embed/gmy6L9vHTbo","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"cb27d06d-613c-4305-a4b2-4d7f195a68a8","name":"Basic Calculator Ii","slug":"basic-calculator-ii","type":1}],"next":{"id":"be2bd28e-f10a-42c6-a368-cd78fba49a7f","name":"Basic Calculator Ii MCQ","type":0,"slug":"basic-calculator-ii-mcq"},"prev":{"id":"cde85b0f-3a4a-4d24-88f7-a551a25714bc","name":"Basic Calculator","type":3,"slug":"basic-calculator"}}}
plane

Editor


Loading...

Basic Calculator Ii

medium

1. Given a string s which represents an expression, evaluate this expression and return its value. 2. while dividing (/) numbers discard the decimal part.Example 3/2 should be 1 insteed of 1.5

Constraints

1. 1 <= s.length <= 3 * 10^5 2. s consists of digits and operators ('+', '-', '*', '/') separated by some number of spaces. 3. All the integers in the expression are non-negative integers.

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

3+3/2*3-2

Sample Output

4

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode