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

  • 相关阅读:
    不同版本strtotime("2016-09-04")输出不同问题
    Jquery,YUI这个著名js库名称作用的理解
    函数和方法
    js的关联数组
    windows信息
    改centos7的网卡名
    GIT命令
    安装时遇到:正在尝试其它镜像。 http://mirrors.btte.net/centos/7.2.1511/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#6
    本地怎样访问虚拟机上的服务器
    yolo
  • 原文地址:https://www.cnblogs.com/danny1221/p/4591363.html
Copyright © 2011-2022 走看看