zoukankan      html  css  js  c++  java
  • 1163

    1163 - Bank Robbery
     

    In one very cold morning, Mark decides to rob a bank. But while trying hacking into the security system, he found that it is locked by some random value. He also found a pattern on the random number, that is if he chops off the last digit of a number A, he gets a new number B. Then he calculates (A-B). He checked the first few numbers of the security system which exactly equals (A-B). Being very excited to have found the pattern, he learns that there are like 500 levels on the security system. He calculated all those numbers by hand but took a lot of time. As a sign of his accomplishment he left a note on the vault stating the pattern. You were the first officer on the crime scene and you've obtained the note. So if you can figure out A from (A-B), you can rob the bank very quick!

    By the way, Mark succeeded in robbing the bank but had a heart attack on the getaway car and crashed.

    Input

    Input starts with an integer T (≤ 500), denoting the number of test cases.

    Each line contains a single positive integer between 10 and 1018 (inclusive), giving the value of A-B.

    Output

    For each case, print the case number and the possible values of A in ascending order. Separate consecutive numbers with a single space.

    Sample Input

    Output for Sample Input

    4

    31

    18

    12

    17

    Case 1: 34

    Case 2: 19 20

    Case 3: 13

    Case 4: 18

    题意:给出A-B,求A, B为A去掉最后一位形成的数。

    分析:B = A / 10, 设A的最后一位为x, A-B的值为n(已知), B * 10 + x - B = n, 即9 * B = n - x; 而 x的取值为0 到9. A = (n - x)* 10 / 9 + x。

    代码:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>
    typedef unsigned long long ll;///注意是无符号位长整型,有符号位长整型会溢出。
    #define N 100
    using namespace std;
    ll n;

    int main()
    {
    int T, cas;
    ll a[N];

    scanf("%d", &T);

    cas = 0;

    while(T--)
    {
    cas++;
    memset(a, 0, sizeof(a));

    scanf("%llu", &n);

    int k = 0;
    for(int i = 0; i <= 9; i++)
    {
    if((n - i) % 9 == 0)
    a[k++] =(n-i)*10/9 + i;
    }
    sort(a, a+k);///输出要求按升序排列。

    k = unique(a, a+k) - a;///类属性算法unique的作用是从输入序列中“删除”所有相邻的重复元素。
    printf("Case %d:", cas);
    for(int i = 0; i < k; i++)
    printf(" %llu", a[i]);

    printf(" ");

    }
    return 0;
    }

  • 相关阅读:
    怪异恼人的java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream问题的解决
    Spring3的quartz定时任务
    HTML模板
    SpringMVC 下载XLS文档的设置
    若想在当前路径下去运行非当前路径下的.class文件(即java可执行文件),该如何操作?
    霍金去世 享年76岁
    Github全面学习笔记
    Github上如何在Fork到的开源项目中提交Pull requests?
    Github中如何Fork开源项目?
    Java永久代去哪儿了
  • 原文地址:https://www.cnblogs.com/dll6/p/7646170.html
Copyright © 2011-2022 走看看