寒假作业3


1,实验代码

include <stdio.h>

int main (void) {
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;
}
2,设计思路

3,问题
这个题目比较难,我是看了助教的答案写的,问题就是我认为我的能力还没有上来。
4,pta截图

原文地址:https://www.cnblogs.com/he932206959/p/10411933.html