有没有好心人帮我跑一下UVA1586,我没有账号跑不了,注册不了账号
// 习题 3-2 分子量
#include<stdio.h>
#include<string.h>
char s[1000];
int n;
bool A(char ch){
switch(ch){
case 'C':
case 'H':
case 'O':
case 'N':return true;
default:return false;
}
}
float getAw(char ch){
switch(ch){
case 'C':return 12.01;
case 'H':return 1.008;
case 'O':return 16.00;
case 'N':return 14.01;
}
}
int main(){
scanf("%d", &n);
fflush(stdin);
while(n--){
//printf("%d:\n", n+1);
float total = 0;
gets(s);
for(int i=0;i<strlen(s);i++){
if(A(s[i])){
int sum=0;
bool isNum = false;
for(int j=i+1;j<strlen(s);j++)
if(!A(s[j])){
sum = sum*10+s[j]-'0';
isNum = true;
}
else
break;
if(!isNum)
sum=1;
total += sum*getAw(s[i]);
}
}
printf("%.3f\n", total);
}
return 0;
}