编程总结3
题目3: 抓老鼠啊~亏了还是赚了?
我的代码:
include<stdio.h>
int money=0;
void search(char a,int p){
if(a=='X'){
if(p==2) p=1;
else p=0;
printf("U");
}else if(a=='T'){
if(p==2) p=1;
else p=3;
printf("D");
money=money+7;
}else if(a=='C'){
p=2;
printf("!");
money=money-3;
}
}
int main(void){
char s[70];
scanf("%s",s);
int i=0,state=1;
while(s[i]!='$'){
if(state==0){
printf("-");
state=1;
}else if(state==1){
search(s[i],&state);
}else if(state==2){
search(s[i],&state);
}else if(state==3){
printf("-");
state=0;
}
i++;
}
printf("\n%d",money);
}
2.设计思路
3.解题中遇见的难点与解决办法
4.运行结果截图