• UVa


    上题目

    Problem C - 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.

      题意很简单,就是给你一个最多1000位的整数,问你这个数能否被11整除。这里之处使用大数模运算就可以了,具体操作看代码。

    上代码

     1 #include <stdio.h>
     2 #include <string.h>
     3 #define max(x,y) (x > y ?  x : y)
     4 #define MAX (1000+10)
     5 using namespace std;
     6 
     7 char num[MAX];
     8 
     9 int main()
    10 {
    11     int len,i;
    12     long long ans;
    13     //freopen("data.txt","r",stdin);
    14     while(scanf("%s",num),strcmp(num,"0"))
    15     {
    16         len=strlen(num);
    17         ans=0;
    18         for(i=0;i<len;i++)
    19             ans=(ans*10+(num[i]-'0'))%11;
    20         if(!ans) printf("%s is a multiple of 11.
    ",num);
    21         else printf("%s is not a multiple of 11.
    ",num);
    22     }
    23     return 0;
    24 }
    10929
  • 相关阅读:
    Linux常用命令ifconfig的相关信息
    搭建路由实例
    httpclient以json形式参数调用http接口并解析返回的报文
    思考(机遇)
    php 对齐方法
    RequireJS简单介绍即使用
    一周小结(2016-06-06~2016-06-12)
    git介绍及使用
    一周小结(2016-05-30~2016-06-04)
    [转] Mou 一个Markdown工具 语法规则文档(最后)
  • 原文地址:https://www.cnblogs.com/sineatos/p/3247063.html
Copyright © 2020-2023  润新知