• pta寒假作业3


    题目三:捉老鼠啊,亏了还是赚了

    实验代码

        #include <stdio.h>

        #include <stdlib.h>

        int main(void)
        {
           char ch;
           int income=0;
           int unhappy, sad, glad;
           unhappy = sad = glad = 0;
           while( (ch=getchar())!='$' ){
           if(glad>0)

          {
             glad--;
             if(sad>0) sad--;
             if(unhappy>0) unhappy--;
          }
          else{
          if(sad>0&&unhappy==0){
          sad--;
          putchar('-');
          continue;
          }
          else if(unhappy>0&&sad==0){
          unhappy--;
          putchar('-');
          continue;
          }
          else if(sad>0&&unhappy>0)
         {
            sad--;
            unhappy--;
            putchar('-');
            continue;
         }
        }
        if(ch=='T'){
        putchar('D');
        income += 7;
        sad = 2;
        }
        else if(ch=='C'){
        putchar('!');
        income -= 3;
        glad = 2;
        }
        else{
        putchar('U');
        unhappy = 1;
        }
        }
        printf(" %d ",income);
        return 0;
        }

     设计思路:定义变量,天数多要用到while语句,要注意老鼠伤心期和高兴期,还要注意分三种情况,然后分情况计算成本利润,最后根据输出结果是负的还是正的看出捉老鼠亏了还是赚了

    遇到的问题:编译错误

    解决方法:看助教群发的那个这题的解析

  • 相关阅读:
    CentOS7 安装 MySQL 5.7
    Centos7 安装 opencv
    nginx编译支持HTTP2.0
    CentOS 6.5 安装 ffmpeg
    parted 4T磁盘
    nginx upstream
    linux rar 解压忽略带密码压缩包
    那些实用的Nginx规则
    linux 两台服务器共享目录NFS实现
    redis集群搭建
  • 原文地址:https://www.cnblogs.com/1793979463hyx/p/10410981.html
Copyright © 2020-2023  润新知