Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Locale;
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) throws IOException{
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- Scanner input = new Scanner(System.in);
- int T=input.nextInt();
- while (T-- != 0) {
- String str=input.next();
- int length = str.length();
- double mass = 0.0;
- for (int i = 0; i < length; i++) {
- int x = 0;
- char ele = str.charAt(i);
- while ((i+1) < length && Character.isDigit(str.charAt(i+1))) {
- i++;
- x = x * 10 + (str.charAt(i) - '0');
- }
- if (x == 0) x = 1;
- mass = mass + f(ele) * x;
- }
- System.out.println(String.format(Locale.ENGLISH, "%.3f", mass));
- }
- in.close();
- }
- public static double f(char ch) {
- if (ch == 'C') return 12.01;
- else if (ch == 'H') return 1.008;
- else if (ch == 'O') return 16.00;
- else return 14.01;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement