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;
    }

  • 相关阅读:
    separable-sss
    Separable Subsurface Scattering Computer Graphics Forum 2015
    GPU Gems 3》:真实感皮肤渲染技术总结
    Subsurface scattering support in Blinn-Phong material
    vue-3d-model
    Ubuntu16.04 安装显卡驱动 cuda,cudnn
    vue.js three.js component
    imagemagick Selective blur
    Leetcode 201.数字范围按位与
    Leetcode 190.颠倒二进制位
  • 原文地址:https://www.cnblogs.com/danny1221/p/4591363.html
Copyright © 2011-2022 走看看