uva 11879Multiple of 17

来源:互联网 发布:云计算和saas 编辑:程序博客网 时间:2024/05/16 09:10

去掉最后一位,然后对17取余,最后减去最后一位乘以5,再取余17。如果为0输出1,否则为0。

#include <iostream>#include <stdlib.h>#include <string.h>#include <stdio.h>using namespace std;int main(){    char s[210];    int a[210];    while(gets(s)!=NULL)    {        if(s[0]=='0')            break;        int i,len=strlen(s);        for(i=0; i<len; i++)            a[i]=s[i]-'0';        int s=0;        for(i=0; i<len-1; i++)        {            s=s*10+a[i];            s=s%17;        }        s=(s-a[i]*5)%17;        if(s)            puts("0");        else            puts("1");    }    return 0;}


原创粉丝点击