toj 4607 Multiple of 17
2016-08-09 11:35
357 查看
toj 4607 Multiple of 17
时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte总提交: 33 测试通过:17
描述
Theorem: If you drop the last digit d of an integer n (n10), subtract 5d from the remaining integer, then the difference is a multiple of 17 if and only if n is a multiple of 17.For example, 34 is a multiple of 17, because 3-20=-17 is a multiple of 17; 201 is not a multiple of 17, because 20-5=15 is not a multiple of 17.
Given a positive integer n, your task is to determine whether it is a multiple of 17.
输入
There will be at most 10 test cases, each containing a single line with an integer n ( 1n10100). The input terminates with n = 0, which should not be processed.输出
For each case, print 1 if the corresponding integer is a multiple of 17, print 0 otherwise.样例输入
34201
2098765413
1717171717171717171717171717171717171717171717171718
0
样例输出
10
1
0
#include <iostream> #include <cstdio> using namespace std; int main() { char s[10000]; while(scanf("%s", s) && (s[0] != '0')) { int sum = 0; for(int i = 0; s[i] != '\0'; i++) { sum = (sum * 10 +s[i] - '0'); sum %= 17; } if(sum == 0) printf("1\n"); else printf("0\n"); } return 0; }
相关文章推荐
- uva 11879 Multiple of 17
- UVa 11879 - Multiple of 17
- uva 11879 - Multiple of 17
- UVA 11879 Multiple of 17
- UVa 11879 - Multiple of 17
- multiple definition of XXX情况分析
- tomcat 启动动重复Multiple Contexts have a path of "/xxxx"问题解决
- 【转】解决多文件编译中连接错误 multiple definition of*****
- 【算法题】Multiples of 3 and 5
- 设计模式(17)-Chain of Responsibility Pattern
- 总结了解决multiple definition of的方法
- 【Project Euler 1】Multiples of 3 and 5
- Leetcode 17 Letter Combinations of a Phone Number
- leetcode 17 Letter Combinations of a Phone Number
- 扰人的异常2: Input length must be multiple of 8 when decrypting with padded cipher
- [转]gcc交叉编译错误之一: multiple definition of
- LightOJ 1135 - Count the Multiples of 3
- tibco.ems.illegalstateexception illegal use of receive() from multiple threads
- Linear regression of multiple features in Tensorflow
- 编译时出现multiple definition of `xxxxxx'的解决办法