Uva1586-Molar Mass-分子量

题目链接https://vjudge.net/problem/UVA-1586

给出一种物质的分子式,(不带括号),求分子量。本题中的分子式只包含4中原子,分别为C,H,O,N,原子量分别为12.01,1.008,16.00,14.01。例如,C6H5OH的分子量为94.108

The quantity number n which is represented after thechemical symbol would be omitted when the number is 1 (2 ≤ n ≤ 99).注意后面数n的范围

#include
#include
#include
double mass(char c){
    if(c=='C') return 12.01;
    if(c=='H') return 1.008;
    if(c=='O') return 16.00;
    if(c=='N') return 14.01;
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        char s[81];
        scanf("%s",s);
        int len=strlen(s);
        double molar=0.0;
        int i=1;
        while(i
1、isdigit()函数的运用

2、最后一个if的判断

你可能感兴趣的:(UVa)