zoukankan      html  css  js  c++  java
  • 2019第十届蓝桥杯C/C++ A组省赛 —— 第一题:平方和

    试题 A: 平方和

    本题总分:5 分

    【问题描述】
    小明对数位中含有 2、0、1、9 的数字很感兴趣,在 1 到 40 中这样的数包括 1、2、9、10 至 32、39 和 40,共 28 个,他们的和是 574,平方和是 14362。注意,平方和是指将每个数分别平方后求和。
    请问,在 1 到 2019 中,所有这样的数的平方和是多少?
    【答案提交】
    这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一 个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。
    提示:如果你编写程序计算,发现结果是负的,请仔细检查自己的程序, 不要怀疑考场的编程软件。

    Code

    /*
                                    ^....0
                                   ^ .1 ^1^
                                   ..     01
                                  1.^     1.0
                                 ^ 1  ^    ^0.1
                                 1 ^        ^..^
                                 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.1
                       01     10  1.1                                      ^^^1111110
                       010    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.         ^.1
                       1 ^      11                             1.                ^^^     ^ ^        ..^
                      ^..^      ^1                             ^.^               ^^^       .0       ^.0
                      0..^      ^0                              01               ^^^       ..      0..^
                     1 ..        .1                             ^.^              ^^^       1 ^  ^0001
                    ^  1.        00                              0.             ^^^        ^.0 ^.1
                    . 0^.        ^.^                             ^.^            ^^^         ..0.0
                   1 .^^.         .^                  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^     ^               01
         1 0             ^.               00.0^              ^00000   1.00.1              11
         . 1              0               1^^0.01                      ^^^                01
          .^              ^                1   1^^                                       ^.^
        1 1                                                                              0.
        ..                                                                              1 ^
         1                                                                               1
       ^ ^                                                                             .0
       1                                                                             ^ 1
       ..                                                          1.1            ^0.0
      ^ 0                                                           1..01^^100000..0^
      1 1                                                            ^ 1 ^^1111^ ^^
      0 ^                                                             ^ 1      1000^
      .1                                                               ^.^     .   00
      ..                                                                1.1    0.   0
      1.                                                                  .    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;
    }
    
  • 相关阅读:
    HashMap 的数据结构
    JVM的内存区域划分
    分库分表的基本思想
    分表与分库使用场景以及设计方式
    千万数据的分库分表(一)
    用c++实现快速排序和归并排序
    如何查看python版本号?
    python的正则表达式
    python3的队列,比python2更好
    markdown如何插入代码?
  • 原文地址:https://www.cnblogs.com/AlexKing007/p/12338238.html
Copyright © 2011-2022 走看看