3 solutions
- 1
Information
- ID
- 487
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 1
- Tags
- # Submissions
- 39
- Accepted
- 28
- Uploaded By
#include<bits/stdc++.h> using namespace std;
int main(){ long long n,s=0,a,b; cin>>n; for(int i=1;i<=n;i++){ b=i; for(int j=1;j<=i;j++){ a=b%10;
if(a==1){
s++;
}
b=(b-a)/10;}
}
cout<<s;
}
//实话实说,这题真的不难
#include <bits/stdc++.h>
using namespace std;
int n;
int count(int x){//我爱自定义函数
int cnt=0;//记录1的个数
while(x){
int k=x%10;
if(k==1) cnt++;
x/=10;
}
return cnt;
}
int main(){
cin>>n;
int ans=0;
for(int i=1;i<=n;i++) ans+=count(i);
cout<<ans<<endl;
return 0;//华丽结尾
}
By signing up a ZXOJ universal account, you can submit code and join discussions in all online judging services provided by us.