ColorlessSilver 2014-12-17 06:16 采纳率: 0%
浏览 3336
已结题

一道算法基础题 uva1586

题目链接在这儿 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=830&page=show_problem&problem=4461

我自己做的代码如下 但是通不过 测了好多数据都没问题

 #include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int n;
    char str[1000][1000];
    double arr[1000];
    while (scanf("%d", &n) != EOF)
    {
        getchar();
        for (int i = 0; i < n; i++){
            gets(str[i]);
            double sum = 0;
            double thisEle = 0;
            double orign = 0;
            for (int j = 0; j < strlen(str[i]); j++){
                if (str[i][j] == 'C'){
                    sum += thisEle;
                    thisEle = 12.01;
                }
                else if (str[i][j] == 'H'){
                    sum += thisEle;
                    thisEle = 1.008;
                }
                else if (str[i][j] == 'O'){
                    sum += thisEle;
                    thisEle = 16.00;
                }
                else if (str[i][j] == 'N'){
                    sum += thisEle;
                    thisEle = 14.01;
                }
                else{
                    if (str[i][j - 1] >= 48 && str[i][j - 1] <= 57){
                        double temp = 10 * thisEle;
                        thisEle = temp + (str[i][j] - 48)*orign;
                    }
                    else{
                        orign = thisEle;
                        thisEle *= (str[i][j] - 48);
                    }
                }
            }
            sum += thisEle;
            arr[i] = sum;
        }
        for (int i = 0; i < n; i++){
        printf("%.3lf\n", arr[i]);
        }
    }
}
  • 写回答

1条回答

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?