抓老鼠啊~亏了还是赚了(PTA)

在这里插入图片描述
在这里插入图片描述

import java.util.Scanner;
public class x{
    
    
    public static void main(String[] args){
    
    
        Scanner sc=new Scanner(System.in);
        int n=1,happy=0, unhappy=0,a=0,b=0,sad=0;
        char[] input=sc.nextLine().toCharArray();
        char ch=input[0];
        int i=0;
        while((ch=input[i])!='$'){
    
    
            if(n==1)
                switch(ch){
    
    
                    case 'X': System.out.printf("U");unhappy=1;break;
                    case 'T': System.out.printf("D");sad=2;a++;b++;break;
                    case 'C': System.out.printf("!");happy=2;b++;break;
                }
            else
                System.out.printf("-");
            if(happy>0) {
    
    
                happy--;
                n=1;
                unhappy=0;
                sad=0;
            }
            else if(happy>0&&unhappy>0){
    
    
                happy--;
                unhappy--;
                n=1;
            }
            else if(happy>0&&sad>0){
    
    
                happy--;
                sad--;
                n=1;
            }
            else if (happy<=0&&unhappy>0){
    
    
                happy++;
                n=0;
            }
            else if(happy<=0&&sad>0){
    
    
                sad--;
                n=0;
            }
            else if(happy==0&&unhappy==0&&sad==0)
                n=1;
            i++;
        }
        System.out.printf("\n%d",a*10-b*3);
    }
}

猜你喜欢

转载自blog.csdn.net/m0_47470899/article/details/110202178