题目描述
给定一个很大的整数,我想知道它能否被9整除。
输入
有t组测试数据,每组数据给定一个整数N不存在前导0。(1 <= t <= 20,1 <= N <= 10^200)。
输出
对每组测试数据,若N可以被9整除,输出1,反之输出0。
样例输入
3
111111111111111111111111111111
6666666666666666
9999999999999999999999999999
样例输出
0 0 1
题解:能被9整出,也就是各位数字之和能被9整除
代码:
1 #include<cstdio> 2 #include<cstring> 3 int main() 4 { 5 int t; 6 char a[300]; 7 scanf("%d",&t); 8 while(t--) 9 { 10 scanf("%s",a); 11 int len=strlen(a); 12 int sum=0; 13 for(int i=0;i<len;i++) 14 sum+=a[i]-'0'; //这里将字符变成数字求和 15 if(sum%9==0) printf("1 "); 16 else printf("0 "); 17 } 18 return 0; 19 }