1451: 幸运数字

xiaoxiao2021-02-28  102

1451: 幸运数字

Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 61   Solved: 52 上一题 Submit Status 下一题

Description

有的人喜欢收集邮票,有的人喜欢收集CD,有的人喜欢收集书…… Gardon也有收集癖,然而他收集的是数字,而且是那些在他看来非常幸运的数字。Gardon觉得,如果一个数字模它的各个数位上的数字之和为0的话,那它就是一个幸运数字。比如说数字18就是一个幸运数字。因为它各个数位上的数字之和为1+8=9,18模9等于0。 Gardon是个怕麻烦的人,他不想自己去计算一个数字是不是幸运数字。所以作为Gardon的好朋友,你必须写个程序帮助他。

Input

有多组测试数据,每组数据输入一个整数n(1<=n<=1000000000),输入以文件结束。

Output

如果数字 n 是幸运数字,输出 ”yes” ,否则输出 ”no”

Sample Input

11 18

Sample Output

no yes

#include <iostream> #include <cstdio> int main(){ long long n=0; int sum=0; char c; while((c=getchar())){ if(c=='\n'||c==EOF) { if(n!=0) if(n%sum==0) printf("yes\n"); else printf("no\n"); n=0;sum=0; if(c==EOF){ break; } continue; } sum+=(c-48); n=n*10+(c-48); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-46745.html

最新回复(0)