赞
踩
如下的 10 行数据,每行有 10 个整数,请你求出它们的乘积的末尾有多少个零?
5650 4542 3554 473 946 4114 3871 9073 90 4329 2758 7949 6113 5659 5245 7432 3051 4434 6704 3594 9937 1173 6866 3397 4759 7557 3070 2287 1453 9899 1486 5722 3135 1170 4014 5510 5120 729 2880 9019 2049 698 4582 4346 4427 646 9742 7340 1230 7683 5693 7015 6887 7381 4172 4341 2909 2027 7355 5649 6701 6645 1671 5978 2704 9926 295 3125 3878 6785 2066 4247 4800 1578 6652 4616 1113 6205 3264 2915 3966 5291 2904 1285 2193 1428 2265 8730 9436 7074 689 5510 8243 6114 337 4096 8199 7313 3685 211
本题如果计算出总和再数0的数量,会超出19位,因此可以通过每进行一次乘法判断一下末尾是否有0,如果有0,则给count加1,并将该数除以10.
- #include<bits/stdc++.h>
- using namespace std;
-
- int main(){
- long long int sum;
- int a[101], i, count=0;
- for(i=0;i<100;i++){
- cin>>a[i];
- sum*=a[i];
- if(sum%10==0){
- sum=sum/10;
- count++;
- }
- }
- //cout<<sum;
- cout<<count;
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。