为了账号安全,请及时绑定邮箱和手机立即绑定

UVA-1586不知道是哪里出错,总是wa

UVA-1586不知道是哪里出错,总是wa

慕用7336610 2018-09-21 22:58:08
InputYour program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case is given in a single line, which contains a molecular formula as a string. The chemical symbol is given by a capital letter and the length of the string is greater than 0 and less than 80. The quantity number n which is represented after the chemical symbol would be omitted when the number is 1 (2n99) . OutputYour program is to write to standard output. Print exactly one line for each test case. The line should contain the molar mass of the given molecular formula. Sample Input 4  C  C6H5OH  NH2CH2COOH  C12H22O11 Sample Output 12.010  94.108  75.070  342.296#include<iostream>#include<string.h>#include<ctype.h>#include<iomanip>using namespace std;int main(){int i,n,k,m,d,f;double s;char a[105][90];    while(cin>>n)    { memset(a,0,sizeof(a));        for(i=0;i<n;i++)            cin>>a[i];            for(i=0;i<n;i++)        {   m=strlen(a[i]);        s=0;            for(k=0;k<m;k++)            {if(isalpha(a[i][k])==1&&isdigit(a[i][k+1])==1)              {{d=a[i][k+1]-'0';                  for(f=1;;f++)    {if(isdigit(a[i][k+f+1])==1)d=d*10+(a[i][k+f+1]-'0');else break;}}                switch(a[i][k])                {case'C':s+=12.01*d;break;                case'H':s+=1.008*d;break;                case'O':s+=16.00*d;break;                case'N':s+=14.01*d;break;}}                if(isalpha(a[i][k])==1&&isdigit(a[i][k+1])!=1)                switch(a[i][k])                {case'C':s+=12.01;break;                case'H':s+=1.008;break;                case'O':s+=16.00;break;                case'N':s+=14.01;break;}                if(isdigit(a[i][k])==1)                    continue;            }            cout<<setiosflags(ios::fixed)<<setprecision(3)<<s<<endl;        }    }    return 0;}
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 1202 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信