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

  • 相关阅读:
    90个常用词根,30个前缀30个后缀
    七、图形与图像处理(1)
    解决Android SDK下载和更新失败的方法(Win系统) 和离线安装
    IT技术网站汇总
    css padding和margin的百分比
    div无法跟随内容的增加而拉伸
    html元素被隐藏在后面
    cron 执行php文件
    cron 编辑器修改
    Eclipse PHP 代码无法自动提示函数
  • 原文地址:https://www.cnblogs.com/danny1221/p/4591363.html
Copyright © 2011-2022 走看看