UVA 10929

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1870

题意为判断一个数是否能被11整除,这里用割减法,存为数组,再从高位开始,一次减去11,看是否能减完

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 void zhuanhua(char *s,int *a)
 4 {
 5  int i=0;
 6  while(*s)
 7       {
 8        a[i]=(*s)-'0';
 9        i++;
10        s++;
11       }
12 }//把字符转化为数值存入数组
13 int main()
14 {
15  int i,len,bb[1010],ans[1010],a;
16  char s[1010];
17  while(scanf("%s",s),strcmp(s,"0"))
18       {
19        len=strlen(s)-1;
20        zhuanhua(s,bb);
21        for(i=0;i<len;i++)
22           {
23            a=bb[i]*10+bb[i+1];
24            while(a>=11)
25               a-=11;
26            bb[i+1]=a;//从高位往低位依次割减,减到最后为0者就是能被11整除的
27           }
28        if(a!=0)
29          printf("%s is not a multiple of 11.\n",s);
30        else 
31              printf("%s is a multiple of 11.\n",s);
32             
33       }
34 return 0;
35 }

 

转载于:https://www.cnblogs.com/huzhenbo113/articles/2915908.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值