• A water problem HDU


     Two planets named Haha and Xixi in the universe and they were created with the universe beginning. 

     There is 73 days in Xixi a year and 137 days in Haha a year. 

     Now you know the days N after Big Bang, you need to answer whether it is the first day in a year about the two planets.

    Input

     There are several test cases(about 5 huge test cases). 

     For each test, we have a line with an only integer N(0N), the length of N is up to 10000000.

    Output

     For the i-th test case, output Case #i: , then output "YES" or "NO" for the answer.

    Sample Input

    10001
    0
    333

    Sample Output

    Case #1: YES
    Case #2: YES
    Case #3: NO

    题意:

    若输入数字能整除73和137,输出YES;否则NO

    输入数字位数上限为1e7

    思路:

    单看数据范围就知道一定要用字符串操作,大数相除,模拟除法运算过程即可

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 char a[10000005];
     5 
     6 int main()
     7 {
     8     int i, len, flag1, flag2;
     9     int x = 73, y = 137, t;
    10     int cas = 0;
    11 
    12     while(~scanf("%s", a))
    13     {
    14         len = strlen(a);
    15         t = 0;
    16         flag1 = 0;
    17         flag2 = 0;
    18 
    19         for(i = 0; i < len; i++)
    20         {
    21             t = (t * 10 + a[i] - '0') % x;
    22         }
    23         if(t==0) flag1 = 1;
    24 
    25         t = 0;
    26         for(i = 0; i < len; i++)
    27         {
    28             t = (t * 10 + a[i] - '0') % y;
    29         }
    30         if(t==0) flag2 = 1;
    31 
    32         if(flag1 && flag2) printf("Case #%d: YES
    ", ++cas);
    33         else printf("Case #%d: NO
    ", ++cas);
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    各种alloc傻傻分不清楚
    嵌入式开发一般流程
    谈谈看门狗在嵌入式中的用法
    基于开发板的二次嵌入式开发
    谈一谈接口电路
    学习ucos和ARM体系结构的路线图
    寻找链表的中位节点(利用快慢指针)
    水箱容积问题
    盛水最多的容器
    数据结构与算法分析C语言描述第二版第79页
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11370125.html
Copyright © 2020-2023  润新知