现在有一个整数A( 0 < A ≤ 1000000000)
一行一个正整数A。
一行一个正整数。
125
3
305160
2
#include
using namespace std;
int ws(int i){
long long x;
for(x=0;i>0;x++){
i/=10;
}
return x;
}
int main(){
int a,ans=0;
cin>>a;
if(a%10==5){
for(int z=1;z<=a;z++){
if(a%5==0){
a/=5;
}else{
cout<return 0;
}
}
}else{
for(int z=1;z<=ws(a);z++){
int m=pow(10,z);
if(a%m/pow(10,z-2)==0){
ans++;
}
}
cout<return 0;
}
return 0;
}
请帮忙看看谢谢!
可能是对于0的数量的统计的判断过于复杂了,可以每次进行a对10求余求出个位数是否为0,逐个数位进行判断即可,修改如下:
#include<bits/stdc++.h>
using namespace std;
int ws(int i){
long long x;
for(x=0;i>0;x++){
i/=10;
}
return x;
}
int main(){
int a,ans=0;
cin>>a;
if(a%10==5){
for(int z=1;z<=a;z++){
if(a%5==0){
a/=5;
}else{
cout<<z;
return 0;
}
}
}else{
// for(int z=1;z<=ws(a);z++){
// int m=pow(10,z);
// if(a%m/pow(10,z-1)==0){
//
// ans++;
// printf("ws(a)=%d,pow(10,z-1)=%d,m=%d,a%%m/pow(10,z-1)=%d,ans=%d\n",ws(a),pow(10,z-1),m,a%m/pow(10,z-1),ans);
// }
// }
if(a==0){
ans=1;
}else{
int single = a%10;
while(a!=0){
if(single==0){
ans++;
}
a=a/10;
single = a%10;
}
}
cout<<ans;
return 0;
}
return 0;
}
C++实现:
#include <iostream>
#include <string>
using namespace std;
int main() {
int aa;
cin >> aa;
if (aa % 10 == 5) {
int result = 0;
while (aa % 5 == 0) {
result++;
aa /= 5;
}
cout << result << endl;
} else {
string str = to_string(aa);
int length = str.length(), result = 0;
for (int i = 0; i < length; i++) {
if (str[i] == '0') {
result++;
}
}
cout << result << endl;
}
return 0;
}
如果我的回答对你有帮助,还望采纳!
#include<bits/stdc++.h>
using namespace std;
int main() {
long long a, ans = 0;
cin >> a;
if (a % 10 == 5) {
for (int z = 1; z <= a; z++) {
if (a % 5 == 0) {
a /= 5;
} else {
cout << z;
return 0;
}
}
} else {
for (int z = 1; z <= log10(a) + 1; z++) {
long long m = 1ll << (2 * z);
if ((a / m) % 10 == 0) {
ans++;
}
}
cout << ans;
return 0;
}
return 0;
}