• Codeforces Round #570 (Div. 3 )A


    A. Nearest Interesting Number

    题目链接:http://codeforces.com/contest/1183/problem/A

    题目:

    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 n such that n≥a and nis minimal.
    Input

    The only line in the input contains an integer a(1≤a≤1000).
    Output

    Print the nearest greater or equal interesting number for the given number a. In other words, print the interesting number n such that n≥a and n is minimal.
    Examples
    Input
    432
    Output
    435

    Input
    99

    Output
    103
    Input
    237
    Output
    237
    Input
    42
    Output
    44
    题意:
    Polycarp知道如果一个数字的数字之和可以被3整除,那么数字本身就可以被3整除。他假设数字,其中数字的总和可被4整除,也有点有趣。 因此,如果数字的总和可以被4整除,他认为正整数是有趣的.Help Polycarp找到给定数字a的最近或更大的有趣数字也就是说,找到有趣的数字n使得n≥a且n是最小的。
    输入

    输入中唯一的行包含一个整数a1≤a≤1000
    输出

    打印给定数字a的最近或更大的有趣数字换句话说,打印有趣数字n使得n≥a且n最小
    思路:用sprintf和sscanf两个库函数,暴力即可,不满足,就加一
    //
    // Created by hanyu on 2019/7/7.
    //
    #include<iostream>
    #include<queue>
    #include<cstring>
    #include<cstdio>
    #include<bits/stdc++.h>
    using namespace std;
    bool change(char z[1005])
    {
        int sum = 0;
        int len = strlen(z);
        for (int i = 0; i < len; i++) {
            sum+=z[i]-'0';
        }
        if(sum%4==0)
            return true;
        else
            return false;
    }
    int main()
    {
        char str[1005];
        while(cin>>str) {
            if(change(str))
                cout<<str<<endl;
            else
            {   int a;
                sscanf(str,"%d",&a);
                 for(int i=0;;i++)
                 {
                     a++;
                     char str1[1005];
                     sprintf(str1,"%d",a);
                     if(change(str1))
                     {
    
                         cout<<str1<<endl;
                         break;
                     } else
                     {
                         sscanf(str1,"%d",&a);
                     }
                 }
            }
        }
        return 0;
    }
  • 相关阅读:
    在Preview中查看man手册
    SVN add file without checkout
    短网址的实现思路
    HTTP 301 与302对于搜索引擎的影响
    解决bitdefender与TortoiseSVN冲突
    在mac中修改主机名
    升级mac os上的maven2至maven3
    访问youtube HTML5测试版本的方法
    Lambda
    107名单。。。
  • 原文地址:https://www.cnblogs.com/Vampire6/p/11148866.html
Copyright © 2020-2023  润新知