{"id":"eae0f62d-8c3c-4368-93a4-e39773b64ded","name":"Baseball Game","description":"You have to keep score for a baseball game with strange rules.\r\nYou are provided an array of string showing operation u have to do.\r\nOperation consists of :- \r\n1. An integer x - Record a new score of x.\r\n2. '+' - Record a new score that is the sum of the previous two scores.\r\n3. 'D' - Record a new score that is double the previous score.\r\n4. 'C' - Invalidate the previous score, removing it from the record.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 <= ops.length <= 1000\r\n2. For operation \"+\", there will always be at least two previous scores on the record.\r\n3. For operations \"C\" and \"D\", there will always be at least one previous score on the record.","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int calPoints(String[] ops) {\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 = calPoints(read.readLine().split(\" \"));\r\n System.out.println(result);\r\n\r\n }\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"5 2 C D +","sampleOutput":"30\r\n","questionVideo":"","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":"30af471d-2ac9-49c9-94fe-95e2264dcb8d","name":"Baseball Game","slug":"baseball-game","type":1}],"next":{"id":"a05e23d3-9842-415a-8e17-59bb82e83580","name":"Baseball Game MCQ","type":0,"slug":"baseball-game-mcq"},"prev":{"id":"c5cf5802-f395-4a2c-828c-9600d1920ff3","name":"Battle Tanks MCQ","type":0,"slug":"battle-tanks-mcq"}}}

Baseball Game

You have to keep score for a baseball game with strange rules. You are provided an array of string showing operation u have to do. Operation consists of :- 1. An integer x - Record a new score of x. 2. '+' - Record a new score that is the sum of the previous two scores. 3. 'D' - Record a new score that is double the previous score. 4. 'C' - Invalidate the previous score, removing it from the record.

{"id":"eae0f62d-8c3c-4368-93a4-e39773b64ded","name":"Baseball Game","description":"You have to keep score for a baseball game with strange rules.\r\nYou are provided an array of string showing operation u have to do.\r\nOperation consists of :- \r\n1. An integer x - Record a new score of x.\r\n2. '+' - Record a new score that is the sum of the previous two scores.\r\n3. 'D' - Record a new score that is double the previous score.\r\n4. 'C' - Invalidate the previous score, removing it from the record.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 <= ops.length <= 1000\r\n2. For operation \"+\", there will always be at least two previous scores on the record.\r\n3. For operations \"C\" and \"D\", there will always be at least one previous score on the record.","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int calPoints(String[] ops) {\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 = calPoints(read.readLine().split(\" \"));\r\n System.out.println(result);\r\n\r\n }\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"5 2 C D +","sampleOutput":"30\r\n","questionVideo":"","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":"30af471d-2ac9-49c9-94fe-95e2264dcb8d","name":"Baseball Game","slug":"baseball-game","type":1}],"next":{"id":"a05e23d3-9842-415a-8e17-59bb82e83580","name":"Baseball Game MCQ","type":0,"slug":"baseball-game-mcq"},"prev":{"id":"c5cf5802-f395-4a2c-828c-9600d1920ff3","name":"Battle Tanks MCQ","type":0,"slug":"battle-tanks-mcq"}}}
plane

Editor


Loading...

Baseball Game

easy

You have to keep score for a baseball game with strange rules. You are provided an array of string showing operation u have to do. Operation consists of :- 1. An integer x - Record a new score of x. 2. '+' - Record a new score that is the sum of the previous two scores. 3. 'D' - Record a new score that is double the previous score. 4. 'C' - Invalidate the previous score, removing it from the record.

Constraints

1. 1 <= ops.length <= 1000 2. For operation "+", there will always be at least two previous scores on the record. 3. For operations "C" and "D", there will always be at least one previous score on the record.

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

5 2 C D +

Sample Output

30

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode