You can say 11

本文介绍了一种用于判断任意长度数字是否为11的倍数的算法,并提供了完整的C++实现代码。该算法通过对输入数字的奇数位与偶数位分别求和并比较其差值是否为11的倍数来确定原数字是否能被11整除。

You can say 11
Time Limite: 1 second


Introduction to the problem

Your job is, given a positive number N, determine if it is a multiple of eleven.

Description of the input

The input is a file such that each line contains a positive number. A line containing the number 0 is the end of the input. The given numbers can contain up to 1000 digits.

Description of the output

The output of the program shall indicate, for each input number, if it is a multiple of eleven or not.

Sample input:

112233
30800
2937
323455693
5038297
112234
0

Sample output

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.

 

能被11整除的数。奇数位数的和与偶数位数的和的差能被11整除。

#include <iostream>
#include<stdio.h>
#include<string.h>
#define m 1001
using namespace std;

int main()
{
    char s[m];
    while(gets(s))
    {
        if(strcmp(s,"0")==0)break;
        int a=0,b=0;
        int i;
        int len=strlen(s);
        for(i=0; i<len; i+=2)
            a+=s[i]-'0';
        for(i=1; i<len; i+=2)
            b+=s[i]-'0';

        if((a-b)%11==0)printf("%s is a multiple of 11.\n",s);
        else printf("%s is not a multiple of 11.\n",s);
    }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值