#include<stdio.h>
int main()
{
int m,s,u,h,t;
char c;
s=u=h=t=m=0;
while((ch=getchar())!=$){
if(t==1){
switch(c){
case T:printf("D");s+=2;m+=7;break;
case X:printf("U");u+=1;break;
case C:printf("!");h+=2;m-=3;break;
s=u=h=t=m=0;
while((ch=getchar())!=$){
if(t==1){
switch(c){
case T:printf("D");s+=2;m+=7;break;
case X:printf("U");u+=1;break;
case C:printf("!");h+=2;m-=3;break;
}
else printf("-");
if(h>0)
h--;
t=1;
else if(h>0&&s>0)
h--;
s--;
t=1;
else if(h>0&&u>0)
h--;
u--;
t=1;
else if(h<=0&&s>0)
s--;
t=0;
else if(h<=0&&u>0)
u--;
t=0;
if(h=0&&s=0&&u=0)
t=1;
scanf("%c",&c);
}
printf(" %d",m);
else printf("-");
if(h>0)
h--;
t=1;
else if(h>0&&s>0)
h--;
s--;
t=1;
else if(h>0&&u>0)
h--;
u--;
t=1;
else if(h<=0&&s>0)
s--;
t=0;
else if(h<=0&&u>0)
u--;
t=0;
if(h=0&&s=0&&u=0)
t=1;
scanf("%c",&c);
}
printf(" %d",m);
return 0;
}
设计思路
![](https://img2018.cnblogs.com/blog/1581927/201902/1581927-20190219005225442-629381494.jpg)
本题调试过程碰到问题及解决办法
注意1:当第一次派出老鼠,如果老鼠高兴时,不会出现老鼠不高兴的情况所以可以不用再把s<0,u<0。