zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    关于日志造成的频繁的IO
    PHP
    gitignore
    Linux安装gradle
    Ambari和ClouderManager分析对比
    原生hadoop生态系统组件安装文档
    hive的数据类型和数据模型
    hive概述
    使用binlog和canal从mysql实时抽取数据
    canal概述
  • 原文地址:https://www.cnblogs.com/sineatos/p/3247063.html
Copyright © 2011-2022 走看看