#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char s[20];
scanf("%s", s); double sum = 0;
for (int i = 0; i < strlen(s); i++) {
if (s[i] == ‘C‘) sum += (s[i + 1] - 48) * 12.01;
if (s[i] == ‘H‘)
{
if (s[i + 1] >= ‘0‘&&s[i + 1] <= ‘9‘)
sum += (s[i + 1] - 48) *1.008;
else
sum += 1.008;
}
if (s[i] == ‘O‘)
{
if (s[i + 1] >= ‘0‘&&s[i + 1] <= ‘9‘)
sum += (s[i + 1] - 48) * 16.00;
else
sum += 16.00;
}
}
printf("%.3f", sum);
system("pause");
}
时间: 2024-10-07 17:16:45