You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
p/lqb-19-b-cplus-special-numbers-sum/
问题描述 小明对数位中含有2、0、1、9 的数字很感兴趣(不包括前导0),在1 到 40 中这样的数包括1、2、9、10 至32、39 和40,共28 个,他们的和是574。 请问,在1 到n 中,所有这样的数的和是多少?\n输入格式 输入一行包含两个整数n。\n输出格式 输出一行,包含一个整数,表示满足条件的数的和。\n样例输入 40\n样例输出 574\n评测用例规模与约定 对于20% 的评测用例,1<= n <= 10。 对于50% 的评测用例,1<= n <=100。 对于80% 的评测用例,1<= n <=1000。 对于所有评测用例, 1<=n <=10000。\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool check(int n) { while(n) { int t=n%10; if(t==2||t==0||t==1||t==9) return true; n/=10; } return false; } int main() { int n,ans=0; cin>>n; for(int i=1;i<=n;i++) { if(check(i)) ans+=i; } cout<<ans<<endl; return 0; }
https://blog.debuginn.com/p/lqb-19-b-cplus-special-numbers-sum/
Beta Was this translation helpful? Give feedback.
All reactions