抓老鼠啊

一、实验代码:

include <stdio.h>

int main () {
int unhappy = 0, sad = 0, happy = 0, profit = 0;
char c;
while ( ( c = getchar() ) != '$' ) {
if ( unhappy && !happy ) {
printf("-");
--unhappy;
}
else if ( sad && !happy ) {
printf("-");
--sad;
}
else {
if ( happy )
--happy;
if ( c == 'T' ) {
printf("D");
sad = 2;
profit += 7;
}
else if ( c == 'C' ) {
printf("!");
happy = 2;
profit -= 3;
}
else {
printf("U");
unhappy = 1;
}
}
}
printf(" %d", profit);
return 0;
}
二、设计思路
1:按照题中给的意思与字母给出 并定义其中的变量
2:利用if-else语句来变化
三、截图
{{uploading-image-289299.png(uploading...)}}

原文地址:https://www.cnblogs.com/zhouhuahua/p/10400401.html