博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #570 (Div. 3 )A
阅读量:4557 次
发布时间:2019-06-08

本文共 1687 字,大约阅读时间需要 5 分钟。

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 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
#include
#include
#include
#include
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<
<

 

转载于:https://www.cnblogs.com/Vampire6/p/11148866.html

你可能感兴趣的文章
999线监控
查看>>
Redis在python中的使用
查看>>
理解class.forName()
查看>>
九大排序算法再总结
查看>>
Uva10290 - {Sum+=i++} to Reach N
查看>>
每日一小练——数值自乘递归解
查看>>
二叉搜索树 (BST) 的创建以及遍历
查看>>
MyBatis/Ibatis中#和$的区别
查看>>
【JAVASCRIPT】React学习-组件生命周期
查看>>
win 64 文件操作
查看>>
LeetCode : First Bad Version
查看>>
pythone函数基础(14)发送邮件
查看>>
Java的一些好看的
查看>>
Linux 修改文件夹和其中所有文件的权限
查看>>
详解volatile 关键字与内存可见性
查看>>
go 聊天室简单版总结
查看>>
HDU 4258 斜率优化dp
查看>>
Literature review
查看>>
Java 中可变参数
查看>>
PyTorch在64位Windows下的Conda包(转载)
查看>>