以下為我的程式碼
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(){
long long int x,y,z,w,n,m;
int nn;
char in_radish[1000000];
char *p=in_radish;
int times;
int radish;
scanf("%d",×);
for(;times;--times){
scanf("%lld %lld %lld %lld %lld %lld\n",&x,&y,&z,&w,&n,&m);
if(m<=0) printf("bye~Rabbit\n");
gets(in_radish);
p=strtok(in_radish," \n");
for(nn=0;;){
if(p==NULL) break;
radish=atoi(p);
switch(radish){
case 1:
m+=(x-nn*n);
break;
case 2:
m+=(y-nn*n);
break;
case 3:
m-=(z+nn*n);
break;
case 4:
printf("%lld-=(%lld+%d*%lld)=",m,w,nn,n);
m-=(w+nn*n);
printf("%lld\n",m);
++nn;
break;
default:
printf("%lld-=%d*%lld=",m,nn,n);
m-=nn*n;
printf("%lld\n",m);
break;
}
p=strtok(NULL," \n");
if(m<=0){
printf("bye~Rabbit\n");
break;
}
}
if(m>0) printf("%dg\n",m);
}
return 0;
}
我是看 吃什麼蘿蔔(switch) 作運算
是不是我有哪裡沒有注意到... 不然我自己用手算的 都沒有錯阿...?
還是有人有測資可以提供給我試試呢???
我有修改過 是這筆 也正確了~
也有注意到 敘述中 : "先中毒 才吃蘿蔔" ... 但是還是吃WA...
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(){
int x,y,z,w,n,m;
int nn;
char in_radish[1000000];
char *p=in_radish;
int times;
int radish;
scanf("%d",×);
for(;times;--times){
scanf("%d %d %d %d %d %d\n",&x,&y,&z,&w,&n,&m);
if(m<=0) printf("bye~Rabbit\n");
gets(in_radish);
p=strtok(in_radish," \n");
for(nn=0;;){
if(p==NULL) break;
radish=atoi(p);
m-=nn*n;
if(m<=0){
printf("bye~Rabbit\n");
break;
}
switch(radish){
case 1:
m+=x;
break;
case 2:
m+=y;
break;
case 3:
m-=z;
break;
case 4:
m-=w;
nn++;
break;
default:
break;
}
p=strtok(NULL," \n");
if(m<=0){
printf("bye~Rabbit\n");
break;
}
}
if(m>0) printf("%dg\n",m);
}
return 0;
}
我有修改過 是這筆 也正確了~
也有注意到 敘述中 : "先中毒 才吃蘿蔔" ... 但是還是吃WA...
#include
#include
#include
int main(){
int x,y,z,w,n,m;
int nn;
char in_radish[1000000];
char *p=in_radish;
int times;
int radish;
scanf("%d",×);
for(;times;--times){
scanf("%d %d %d %d %d %d\n",&x,&y,&z,&w,&n,&m);
if(m<=0) printf("bye~Rabbit\n");
gets(in_radish);
p=strtok(in_radish," \n");
for(nn=0;;){
if(p==NULL) break;
radish=atoi(p);
m-=nn*n;
if(m<=0){
printf("bye~Rabbit\n");
break;
}
switch(radish){
case 1:
m+=x;
break;
case 2:
m+=y;
break;
case 3:
m-=z;
break;
case 4:
m-=w;
nn++;
break;
default:
break;
}
p=strtok(NULL," \n");
if(m<=0){
printf("bye~Rabbit\n");
break;
}
}
if(m>0) printf("%dg\n",m);
}
return 0;
}
你的 case 1,2,3,4,0
都沒扣掉中毒減損 。