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
  • 相关阅读:
    css3中calc()使用
    垂直居中
    QLineEdit IP地址校验
    UML类图几种关系的总结(网摘)
    如何解压 Mac OS X 下的 PKG 文件(网摘)
    %appdata%目录下配置文件修改
    文件字符串替换
    Qt版权符号显示问题
    Mac OS X 终端命令开启功能
    Qt 无边框拖拽实现
  • 原文地址:https://www.cnblogs.com/sineatos/p/3247063.html
Copyright © 2011-2022 走看看