欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-27 12:45:50
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];.....

抓老鼠啊~亏了还是赚了(PTA)
抓老鼠啊~亏了还是赚了(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);
    }
}

本文地址:https://blog.csdn.net/m0_47470899/article/details/110202178

相关标签: PTA java