其他分享
首页 > 其他分享> > PTA3

PTA3

作者:互联网

include <stdio.h>

int main()
{
char operating;
int profit = 0, Sad = 0, Unhappy = 0, Excited = 0;
int flagOfSad, flagOfUnhappy, flagOfExcited;
while (scanf("%c", &operating) && operating != '$')
{
flagOfSad = flagOfUnhappy = flagOfExcited = 1;
switch (operating)
{
case 'T':
if((Sad == 0 && Unhappy == 0) || (Excited != 0))
{
printf("D");
Sad = 2;
profit += 7;
flagOfSad = 0;
}
else
printf("-");
break;
case 'C':
if ((Sad == 0 && Unhappy == 0) || (Excited != 0))
{
printf("!");
Excited = 2;
profit -= 3;
flagOfExcited = 0;
}
else
printf("-");
break;
case 'X':
if ((Sad == 0 && Unhappy == 0) || (Excited != 0))
{
printf("U");
Unhappy = 1;
flagOfUnhappy = 0;
}
else
printf("-");
break;
}
if (Sad && flagOfSad) Sad--;
if (Excited && flagOfExcited) Excited--;
if (Unhappy && flagOfUnhappy) Unhappy--;
}
printf("\n%d", profit);

return 0;

}

2)设计思路

3)本题调试过程碰到问题及解决办法

解决办法:重新寻找思路

4)运行结果截图

标签:Unhappy,Sad,PTA3,&&,printf,Excited,flagOfSad
来源: https://www.cnblogs.com/luoyuliang/p/10414802.html