zoukankan      html  css  js  c++  java
  • 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就输出这个数。进行取余和取模运算。

  • 相关阅读:
    5.11实例应用
    VS2015调试
    4.4空间平滑
    4.3图像噪声
    4.2 傅里叶变换
    4.1 图像采样
    4.5.实例应用
    关于split和merge出错问题解决
    Ansible用于网络设备管理 part 3 使用NAPALM成品库
    记办公室小机房停电
  • 原文地址:https://www.cnblogs.com/yuanhang110/p/11229283.html
Copyright © 2011-2022 走看看