UVa10929:You can say 11

题目:判断一个数知否能被11整除。
方法:如果一个数的奇数位上的和与偶数位上的和的差可以被11整除,则说明是multiple of 11。

你的任務是,給你一個正整數 N,判定它是否是 11 的倍數。

Input

每列資料有一個正整數N,N 最大可能到 1000 位數。

若 N = 0 代表輸入結束。

Output

對每個輸入的數,輸出是否為 11 的倍數。輸出格式請參考 Sample Output。

Sample InputSample Output
112233
30800
2937
323455693
5038297
112234
0
112233 is a multiple of 11.
30800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
112234 is not a multiple of 11.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	while(1)
	{
		char arr[1001]={0}, str[1001]={0};
		
		gets(arr);
		if(arr[0]-'0'==0 || arr[0]==' ' && arr[1]-'0'==0) break;	//出现"0"或者" 0"时终止
		
		int i, j=0, odd=0, even=0;
		
		for(i=0; i<strlen(arr); i++)
			if(arr[i]>='0' && arr[i]<='9') str[j++]=arr[i];	//将数字放入一个新的阵列
		
		for(i=0; i<strlen(str); i++)
		{
			if(i%2==1) odd+=str[i]-'0';
			else even+=str[i]-'0';
		}
	
		printf("%s is ",str);
		if(abs(odd-even)%11!=0) printf("not ");
		printf("a multiple of 11.\n");
	}
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值