Codeforces Round #570 (Div. 3 )A
Posted vampire6
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
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(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;
以上是关于Codeforces Round #570 (Div. 3 )A的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #316 (Div. 2) B. Simple Game
Codeforces Round #436 E. Fire(背包dp+输出路径)
[ACM]Codeforces Round #534 (Div. 2)