为什么全RE了,求助!!

P1149 [NOIP2008 提高组] 火柴棒等式

``` if(b==0) return a[0]; ```
by C3765428 @ 2019-08-24 10:53:32


@差不多会很久少了
by C3765428 @ 2019-08-24 10:54:19


主函数的if判断也有问题
by C3765428 @ 2019-08-24 10:57:00


##### 附AC代码 ``` #include<iostream> #include<cstdio> using namespace std; int a[10]={6,2,5,5,4,5,6,3,7,6}; int fun(int x){ int s=0; if(x==0) return a[0]; while(x!=0){ s+=a[x%10]; x=x/10; } return s; } int main(){ int a,b,c,n; cin>>n; int ans=0; for(a=0;a<1001;a++) for(b=0;b<1001;b++) if(fun(a)+fun(b)+fun(a+b)+4==n){ ans++; } cout<<ans<<endl; return 0; } ```
by C3765428 @ 2019-08-24 10:57:48


@[C3765428](/space/show?uid=208240) 谢谢!!
by 哈娜 @ 2019-08-24 16:16:31


和你一样,你的错是数组越界
by szyzbo @ 2019-11-03 14:14:16


附ac代码×2: #include <iostream> using namespace std; int a[10]={6,2,5,5,4,5,6,3,7,6}; int hc(int x){ int s=0; do{ s+=a[x%10]; x/=10; }while(x>0); return s; } int main(){ int n,p1,p2,sum,tot,h; tot=h=0; cin>>n; n-=4; for(p1=0;p1<=2000;p1++){ for(p2=0;p2<=2000;p2++){ sum=p1+p2,h=0; h=hc(p1)+hc(p2)+hc(sum); if(h==n){ tot++; //cout<<p1<<"+"<<p2<<"="<<sum<<endl; } } } cout<<tot; return 0;}
by fz20181223 @ 2019-11-03 15:06:22


|