ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Round #570 (Div. 3 )A

2019-07-07 23:56:54  阅读:324  来源: 互联网

标签:数字 Polycarp interesting sum 570 Codeforces number Div include


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是最小的。
输入

输入中唯一的行包含一个整数a(1≤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;
}

 

标签:数字,Polycarp,interesting,sum,570,Codeforces,number,Div,include
来源: https://www.cnblogs.com/Vampire6/p/11148866.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有