×

 0 Problem Code: COAD02 Problem link is here Problem Name: Simple Sum Contest Name: CodeAdda Practice Contest – 2 (CPC2016) Author: Yatharth Oza (Username: yatharth100) Difficulty: Easy PREREQUISITES: Math Problem: Here One String is given as a input in each test case. Each String contains some Float numbers join by one character ‘e’. You just need to extract all floats and do sum of all numbers and print output which is correct up to 4 decimal places. Explanation: For this problem we can traverse whole input string by putting one by one character in one temporary string and when ‘e’ comes we will stop and then we can convert string to float and add in ‘Sum’ variable which stores current sum of input. At last we can just return the value of ‘Sum’. After each iteration we make temporary string null and Sum value to 0. If you are doing your code in C then you can make approach like this. But, If you are using JAVA or any object oriented language then it provides directly “split(“e”)” function from which you can make given approach directly. Solution: /*Solution is in JAVA and filename is Main.java */ import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) throws java.lang.Exception { float sum=0,temp; long t; Scanner in=new Scanner(System.in); t=in.nextLong(); while(--t>=0) { sum=0; String str = in.next(); String[] no = str.split("e"); for(int i=0;i
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,631
×3,741
×874
×1

question asked: 29 Mar '16, 18:39

question was seen: 432 times

last updated: 29 Mar '16, 19:22