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;
    }

  • 相关阅读:
    SpringBoot--整合Mybatis
    SpringBoot--使用JDBC连接mysql
    使用docker创建mysql容器
    iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3306 -j DNAT --to-destination 172.17.0.2:3306 ! -i docker0: iptables: No chain/target/match by that name
    SpringBoot--配置文件
    yqq命令
    vim/vm命令后提示错误:Found a swap file by the name ".dockerfile.swp"
    推荐一个十分好看的开源博客系统
    [转]技术的热门度曲线
    逆向学习笔记(2)-这是代码还是数据
  • 原文地址:https://www.cnblogs.com/dll6/p/7646170.html
Copyright © 2011-2022 走看看