• 小刘(第二版)


    第三章

    3.1 uva1585 uvalive3354

    题意:错题0分,对题得分为目前位置连续正确数。求总分。

    思路:模拟

    代码:

    #include <cstdio>
    #include <cstring>
    
    char str[10000];
    int main() {
        int t;
        scanf("%d", &t);
        while (t--) {
            scanf("%s", str);
            int res = 0;
            int now = 0;
            for (int i = 0; str[i]; i++) {
                if (str[i] == 'O') now++;
                else now = 0;
                res += now;
            }
            printf("%d
    ", res);
        }
        return 0;
    }
    View Code

     3.2 uva1586 uvalive3900

    题意:告诉你四种原子的摩尔质量,现告诉你分子式,求分子的摩尔质量(话说是这么说的么?高中化学忘完了。。)

    思路:模拟。最后写成了按字符处理的状态机写法。

    代码:

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    
    double num[5] = {12.01,1.008,16.00,14.01, 0};
    char dict[1000];
    char str[10000];
    
    #define LOG 
    
    int main() {
        int t;
        scanf("%d
    ", &t);
        dict['C'] = 0;
        dict['H'] = 1;
        dict['O'] = 2;
        dict['N'] = 3;
        while (t--) {
            scanf("%s", str);
            int pre = 4;
            int now = 0;
            double res = 0;
            for (int i = 0; str[i]; i++) {
                if ('A' <= str[i] && str[i] <= 'Z') {
                    res += num[pre]*(now==0?1:now); // default 1
                    LOG("pre = %d, now = %d
    ", pre, now);
    
                    now = 0;
                    pre = dict[str[i]];
                }
                if ('0' <= str[i] && str[i] <= '9') {
                    now = now * 10 + str[i] - '0';
                }
            }
            res += num[pre]*(now==0?1:now); // default 1
    
            printf("%.3lf
    ", res);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    冲刺二4
    第十四周总结
    大道至简阅读笔记02
    冲刺二3
    冲刺二2
    大道至简阅读笔记01
    冲刺二1
    第十三周总结
    第一阶段意见评价
    5月23日团队开发日志
  • 原文地址:https://www.cnblogs.com/shinecheng/p/4179848.html
Copyright © 2020-2023  润新知