Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|---|
27754 | 老师 | 数1的个数 | C++ | Accepted | 100 | 0 MS | 252 KB | 260 | 2021-12-18 14:48:30 |
#include<bits/stdc++.h> using namespace std; int n,ans; int count1(int n){ int ans=0; while(n){ if(n%10==1) ans++; n/=10; } return ans; } int main(){ cin>>n; for(int i=1;i<=n;i++){ ans+=count1(i); } cout<<ans<<endl; return 0; }