• Codeforces1183A(A题)Nearest Interesting Number


    Polycarp knows that if the sum of the digits of a number is divisible by 3, then the number itself is divisible by 3. He assumes that the numbers, the sum of the digits of which is divisible by 4, are also somewhat interesting. Thus, he considers a positive integer n interesting if its sum of digits is divisible by 4.

    Help Polycarp find the nearest larger or equal interesting number for the given number a. That is, find the interesting number nn such that n≥a and n is minimal.

    Input

    The only line in the input contains an integer (1a1000).

    Output

    Print the nearest greater or equal interesting number for the given number aa. In other words, print the interesting number nn such that n≥a and n is minimal.

     1 #include<iostream>
     2 using namespace std;
     3 int main() {
     4     int a,n,sum=0,i;
     5     cin>>a;
     6     for(i=a; i<=1005; i++) {
     7         int b=i;
     8         while(b) {
     9             int t=b%10;
    10             b=b/10;
    11             sum+=t;    
    12         }
    13         if(sum%4==0) {
    14             cout<<i;
    15             i=1006;
    16         }
    17         sum=0;
    18     }
    19 }

    思路分析:输入一个数a,将它从a递增来获得它的最小的各位数和能整出4的整数。先求个十百千位数之和,如果和能整除4就输出这个数。进行取余和取模运算。

  • 相关阅读:
    PHP书写规范 PHP Coding Standard
    PHP开发编码规范.
    javascript hasOwnProperty 函数
    PHP::转义与反转义函数 (POST/GET/COOKIE)
    PHP 单一入口程序
    SET_INCLUDE_PATH详细解释
    PHP类命名规范
    管理软件本质论
    数据驱动
    脚本适用场合
  • 原文地址:https://www.cnblogs.com/yuanhang110/p/11229283.html
Copyright © 2020-2023  润新知