2019第十届蓝桥杯C/C++ A组省赛 —— 第一题:平方和
生活随笔
收集整理的這篇文章主要介紹了
2019第十届蓝桥杯C/C++ A组省赛 —— 第一题:平方和
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
試題 A: 平方和
本題總分:5 分
【問題描述】
小明對數(shù)位中含有 2、0、1、9 的數(shù)字很感興趣,在 1 到 40 中這樣的數(shù)包括 1、2、9、10 至 32、39 和 40,共 28 個,他們的和是 574,平方和是 14362。注意,平方和是指將每個數(shù)分別平方后求和。
請問,在 1 到 2019 中,所有這樣的數(shù)的平方和是多少?
【答案提交】
這是一道結(jié)果填空的題,你只需要算出結(jié)果后提交即可。本題的結(jié)果為一 個整數(shù),在提交答案時只填寫這個整數(shù),填寫多余的內(nèi)容將無法得分。
提示:如果你編寫程序計算,發(fā)現(xiàn)結(jié)果是負(fù)的,請仔細(xì)檢查自己的程序, 不要懷疑考場的編程軟件。
Code
/*^....0^ .1 ^1^.. 011.^ 1.0^ 1 ^ ^0.11 ^ ^..^0. ^ 0^.0 1 .^.1 ^0 .........001^.1 1. .111100....01^00 11^ ^1. .1^1.^ ^0 0^.^ ^0..1.1 1..^1 .0 ^ ^00. ^^0.^^ 0 ^^110.^0 0 ^ ^^^10.01^^ 10 1 1 ^^^1110.101 10 1.1 ^^^1111110010 01 ^^ ^^^1111^1.^ ^^^10 10^ 0^ 1 ^^111^^^0.1^ 1....^11 0 ^^11^^^ 0.. ....1^ ^ ^1. 0^ ^11^^^ ^ 1 111^ ^ 0.10 00 11 ^^^^^ 1 0 1.0^ ^0 ^0 ^^^^ 0 0.0^ 1.0 .^ ^^^^ 1 1 .0^.^ ^^ 0^ ^1 ^^^^ 0. ^.11 ^ 11 1. ^^^ ^ ^ ..^^..^ ^1 ^.^ ^^^ .0 ^.00..^ ^0 01 ^^^ .. 0..^1 .. .1 ^.^ ^^^ 1 ^ ^0001^ 1. 00 0. ^^^ ^.0 ^.1. 0^. ^.^ ^.^ ^^^ ..0.01 .^^. .^ 1001 ^^ ^^^ . 1^. ^ ^. 11 0. 1 ^ ^^ 0.0 ^. 0 ^0 1 ^^^ 0.0.^ 1. 0^ 0 .1 ^^^ ...1 1. 00 . .1 ^^^ ..1 1. ^. 0 .^ ^^ ..0. 1. .^ . 0 ..1 1. 01 . . ^ 0^.^ 00 ^0 1. ^ 1 1.0 00 . ^^^^^^ ..^ 00 01 ..1. 00 10 1 ^^.1 00 ^. ^^^ .1.. 00 .1 1..01 ..1.1 00 1. ..^ 10^ 1^ 00 ^.1 0 1 1.1 00 00 ^ 1 ^. 00 ^.^ 10^ ^^1.1 00 00 10^..^ 1. ^. 1.0 1 ^. 00 00 .^^ ^. ^ 1 00 ^0000^ ^ 011 0 ^. 00.0^ ^00000 1.00.1 11. 1 0 1^^0.01 ^^^ 01.^ ^ 1 1^^ ^.^1 1 0... 1 ^1 1^ ^ .01 ^ 1.. 1.1 ^0.0^ 0 1..01^^100000..0^1 1 ^ 1 ^^1111^ ^^0 ^ ^ 1 1000^.1 ^.^ . 00.. 1.1 0. 01. . 1. .^1. 1 1. ^0^ . ^.1 00 01^.0 001. .^*//* Procedural objectives:Variables required by the program:Procedural thinking:Functions required by the program:Determination algorithm:Determining data structure:*/ /* My dear Max said: "I like you, So the first bunch of sunshine I saw in the morning is you, The first gentle breeze that passed through my ear is you, The first star I see is also you. The world I see is all your shadow."FIGHTING FOR OUR FUTURE!!! */ #include <iostream>using namespace std;long long ans=0;bool check(int num){bool flag=false;while(num){int temp=num%10;if(temp==0 || temp==1 || temp==2 || temp==9)flag=true;num/=10;}return flag?true:false; }int main(){int n;cin>>n;for(int i=1;i<n+1;i++)if(check(i))ans+=i*i;cout<<ans<<endl;return 0; }總結(jié)
以上是生活随笔為你收集整理的2019第十届蓝桥杯C/C++ A组省赛 —— 第一题:平方和的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2015年第六届蓝桥杯C/C++ A组国
- 下一篇: 2019第十届蓝桥杯C/C++ A组省赛