• 【luogu P4711 「化学」相对分子质量】 题解


    题目链接:https://www.luogu.org/problemnew/show/P4711

    要细心模拟

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <iostream>
    using namespace std;
    char s[10001];
    int k;
    double nans1, nans2, fans, ffans, nans3, nans4;
    double koushu(char a, char b)
    {
        if(a == 'A')
        {
            if(b == 'g')
            return 108;
            if(b == 'u')
            return 197;
            if(b == 'l')
            return 27;
        } 
        if(a == 'H')
        {
            if(b == '#')
            return 1;
            if(b == 'g')
            return 201;
            if(b == 'f')
            return 178.5;
        }
        if(a == 'C')
        {
            if(b == '#')
            return 12;
            if(b == 'l')
            return 35.5;
            if(b == 'a')
            return 40;
            if(b == 'u')
            return 64;
        }
        if(a == 'N')
        {
            if(b == '#')
            return 14;
            if(b == 'a')
            return 23;
        }
        if(a == 'O')
        {
            if(b == '#')
            return 16;
        }
        if(a == 'F')
        {
            if(b == '#')
            return 19;
            if(b == 'e')
            return 56;
        }
        if(a == 'M')
        {
            if(b == 'g')
            return 24;  
            if(b == 'n')
            return 55;
        }
        if(a == 'S')
        {
            if(b == 'i')
            return 28;
            if(b == '#')
            return 32;
        }
        if(a == 'P')
        {
            if(b == '#')
            return 31;
            if(b == 't')
            return 195;
        }
        if(a == 'K')
        {
            if(b == '#')
            return 39; 
        }
        if(a == 'Z')
        {
            if(b == 'n')
            return 65;
        }
        if(a == 'I')
        {
            if(b == '#')
            return 127; 
        }
        if(a == 'B')
        {
            if(b == 'a')
            return 137;
        }
    }
    bool flag = 0;
    int main()
    {
        cin>>s;
        int len = strlen(s);
        for(int i = 0; i < len; i++)
        {
            if(s[i] == '~')
            {
            	if(s[i+1] > 48 && s[i+1] <= 57 && s[i+2] >= 48 && s[i+2] <= 57)
                {
                	ffans = 18*(10*(s[i+1]-'0')+s[i+2]-'0'); 
    				fans += ffans;
                	break;
    			}//十位数的水 
    			else if(s[i+1] > 48 && s[i+1] <= 57)
    			{
    				ffans = 18*(s[i+1]-'0');
    				fans += ffans;
                	break;
    			}//个位数的水 
    			else if(s[i+1] == 'H')
                            {
    				ffans += 18;
               		        fans += ffans;
                	break; 
    			}//一个水 
            }
    		
            if(s[i] == '(') // 抠括号里的 
            {
                for(int j = i+1; s[j] != ')'; j++)
                {
                    if((s[j] >= 65 && s[j] <= 90) &&(s[j+1] >= 97 && s[j+1] <= 122))
                    {
                        nans3 += koushu(s[j],s[j+1]);
                        if(s[j+2] == '_')
                        nans3 = nans3*(s[j+4]-'0'); 
                        nans1 += nans3;
    		    nans3 = 0;
    		}
                    if((s[j] >= 65 && s[j] <= 90) &&(s[j+1] <= 97 || s[j+1] >= 122))
                    {
                        nans4 += koushu(s[j],'#');
                        if(s[j+1] == '_')
                        nans4 = nans4*(s[j+3]-'0');
                        nans1 += nans4;
                        nans4 = 0;
                    }
                    k = j;
                    i = j+1;//处理完括号,把i调到下一位,否则会重复加
                }
                if(s[k+2] == '_')
                nans1 = nans1*(s[k+4]-'0');
                fans += nans1;
                nans1 = 0;
            }
            if((s[i] >= 65 && s[i] <= 90) &&(s[i+1] >= 97 && s[i+1] <= 122))
            {
                nans2 += koushu(s[i],s[i+1]);
                if(s[i+2] == '_')
                nans2 = nans2*(s[i+4]-'0');
                fans += nans2;
                nans2 = 0;
                continue;
            }
    
            if((s[i] >= 65 && s[i] <= 90) &&(s[i+1] <= 97 || s[i+1] >= 122))
            {
                nans2 += koushu(s[i],'#');
                if(s[i+1] == '_')
                nans2 = nans2*(s[i+3]-'0');
                fans += nans2;
                nans2 = 0;
                continue;
            }
        }
        cout<<fans;
        return 0;
    }
    

    隐约雷鸣,阴霾天空,但盼风雨来,能留你在此。

    隐约雷鸣,阴霾天空,即使天无雨,我亦留此地。

  • 相关阅读:
    PowerShell尝试ssh登录
    PowerShell收发TCP消息包
    powershell对指定IP进行端口扫描
    PowerShell尝试登录ftp
    PowerShell批量扫描IP和端口
    《PowerShell 3.0 Advanced Admin handbook》已于今日上市
    PowerShell尝试登录SQL Server
    Docker 数据卷
    Dockerfile自定义镜像
    Docker 容器操作
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/9197770.html
Copyright © 2020-2023  润新知