zoukankan      html  css  js  c++  java
  • UVa1586 Molar mass

    #include <stdio.h>

    int GetQuantity(char* q, char** p)
    {
        int quantity = 0;
        while (*q && '0' <= *q && *q <= '9')
        {
            quantity = quantity*10 + (*q-'0');
            ++q;
        }
        if (quantity == 0)
            quantity = 1;
        *p = q;
        return quantity;
    }

    int main()
    {
        int T, quantity;
        double mass;
        char str[81], *p;
        scanf("%d", &T);
        while (T--)
        {
            scanf("%s", str);
            mass = 0.0;
            p = str;
            while (*p)
            {
                if (*p == 'C')
                {
                    quantity = GetQuantity(p+1, &p);
                    mass += (12.01*quantity);
                }
                else if (*p == 'H')
                {
                    quantity = GetQuantity(p+1, &p);
                    mass += (1.008*quantity);
                }
                else if (*p == 'O')
                {
                    quantity = GetQuantity(p+1, &p);
                    mass += (16.00*quantity);
                }
                else if (*p == 'N')
                {
                    quantity = GetQuantity(p+1, &p);
                    mass += (14.01*quantity);
                }
                else
                {
                    ++p;
                }
            }
            
            printf("%.3f ", mass);
        }

        return 0;
    }

  • 相关阅读:
    js面试相关
    邮件(一):Springboot+thymeleaf的发邮件部分
    饿了么组件--table组件自定义渲染列,同时伴有v-for和v-if情况
    java开发规范学习
    java发送邮件
    vue垂死挣扎--遇到的问题
    vue学习记录
    matlab---设置背景颜色为白色
    Git push时不需要总输入密码
    我不知道的js(一)作用域与闭包
  • 原文地址:https://www.cnblogs.com/danny1221/p/4591363.html
Copyright © 2011-2022 走看看