zoukankan      html  css  js  c++  java
  • hust 1062 Divisibility

    题目描述

    On the planet Zoop, numbers are represented in base 62, using the digits 0, 1, . . . , 9, A, B, . . . , Z, a, b, . . . , z where A (base 62) = 10 (base 10) B (base 62) = 11 (base 10) . . . z (base 62) = 61 (base 10). Given the digit representation of a number x in base 62, your goal is to determine if x is divisible by 61.

    输入

    The input test file will contain multiple cases. Each test case will be given by a single string containing only the digits ‘0’ through ‘9’, the uppercase letters ‘A’ through ‘Z’, and the lowercase letters ’a’ through ’z’. All strings will have a length of between 1 and 10000 characters, inclusive. The end-of-input is denoted by a single line containing the word “end”, which should not be processed.

    输出

    For each test case, print “yes” if the number is divisible by 61, and “no” otherwise.

    样例输入

    1v3
    2P6
    IsThisDivisible
    end
    

    样例输出

    yes
    no
    no
    

    提示In the first example, 1v3 = 1 × 622 + 57 × 62 + 3 = 7381, which is divisible by 61. In the second example, 2P6 = 2 × 622 + 25 × 62 + 6 = 9244, which is not divisible by 61.

    显然,提示是错误的,不过没关系,不影响我们做题

    #include<iostream>
    #include<cstring>
    #include<string>
    #include<cstdio>
    using namespace std;
    
    int get_num(char x)
    {
        if (x>='0' && x<='9') return x-'0';
        if (x>='A' && x<='Z') return x-'A'+10;
        if (x>='a' && x<='z') return x-'a'+36;
    }
    
    int main()
    {
        char str[10000+10];
        int ans,temp;
        while (scanf("%s",str)!=EOF && strcmp("end",str)!=0)
        {
            int L=strlen(str);
            ans=0;
            temp=1;
            for (int i=L-1;i>=0;i--)
            {
                ans+=(get_num(str[i])*temp)%61;
                ans=ans%61;
                temp=(temp*62)%61;
            }
            if (ans%61) printf("no
    ");
            else printf("yes
    ");
        }
        return 0;
    }

    作者 chensunrise

    至少做到我努力了
  • 相关阅读:
    away3d 4.1 alpha 教程 换装篇 <3> 人物动态换装DEMO
    书本资料汇总
    洪小瑶学IOS(一):准备起航 <ObjectiveC基础教程>笔记
    Flex 4 权威指南 学习笔记
    通过存储过程建立灵活的SQL计划任务
    javascript 未结束的字符串常量
    SQL重复记录查询
    重置数据库自增字段
    C#获取周一、周日的日期 函数类
    C# ,ASP.NET,Winform将数据导出到Execl汇总
  • 原文地址:https://www.cnblogs.com/chensunrise/p/3759907.html
Copyright © 2011-2022 走看看