• 寒假作业3



    #include <stdio.h>
    #include <stdlib.h>
    /**
    输入样例1:  TXXXXC$
    输出样例1:  D--U-!
                4
    输入样例2:  CTTCCX$
    输出样例2:  !DD--U
                11
    **/
    int main()/*老师的程序错了,现在我改对了,当前三天CTX,第四天既有sad,又有unhappy,
    要同时减去1,否者会出错,如,四五天为TT,第四天不派老鼠,T无用,第五天派老鼠,
    则前五天为!DU-D,而按照老师的为!DU--*/
    {
        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;
    }
    /*
    老师的为:
    if(sad>0){
                    sad--;
                    putchar('-');
                    continue;
                }
    if(unhappy>0){
                    unhappy--;
                    putchar('-');
                    continue;
                }
    */
  • 相关阅读:
    Regexp
    Qt Customize QVariant
    Paradox
    Write File
    Division of Line Segment
    How to Get Vertical Line from Point and Line
    IOPS-百度百科
    磁盘的读写-想起了SGA PGA DBWR LGWR...
    记一次备份发起时间延后问题
    V$RMAN_BACKUP_JOB_DETAILS
  • 原文地址:https://www.cnblogs.com/20188703zyj/p/10405743.html
Copyright © 2020-2023  润新知