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
  • 相关阅读:
    Java 基本数据类型
    关于 Java 安装配置文件总结
    Day01
    关于自律!
    Java
    Java
    一年软件开发工作有感!
    如何解决文档复制时候禁止复制限制
    tensorflow tf.keras概述
    jupyter使用说明书
  • 原文地址:https://www.cnblogs.com/sineatos/p/3247063.html
Copyright © 2011-2022 走看看