zoukankan      html  css  js  c++  java
  • 九度OJ1036-空缺数字计算-暴力破解

    题目1036:Old Bill

    时间限制:1 秒

    内存限制:32 兆

    特殊判题:

    提交:3748

    解决:2053

    题目描述:

        Among grandfather's papers a bill was found.
        72 turkeys $_679_
        The first and the last digits of the number that obviously represented the total price of those turkeys are replaced here by blanks (denoted _), for they are faded and are illegible. What are the two faded digits and what was the price of one turkey?
        We want to write a program that solves a general version of the above problem.
        N turkeys $_XYZ_
        The total number of turkeys, N, is between 1 and 99, including both. The total price originally consisted of five digits, but we can see only the three digits in the middle. We assume that the first digit is nonzero, that the price of one turkeys is an integer number of dollars, and that all the
    turkeys cost the same price.
        Given N, X, Y, and Z, write a program that guesses the two faded digits and the original price. In case that there is more than one candidate for the original price, the output should be the most expensive one. That is, the program is to report the two faded digits and the maximum price per turkey for the turkeys.

    输入:

        The first line of the input file contains an integer N (0<N<100), which represents the number of turkeys. In the following line, there are the three decimal digits X, Y, and Z., separated by a space, of the original price $_XYZ_.

    输出:

        For each case, output the two faded digits and the maximum price per turkey for the turkeys.

    样例输入:
    72
    6 7 9
    5
    2 3 7
    78
    0 0 5
    样例输出:
    3 2 511
    9 5 18475
    0
    来源:
    2007年上海交通大学计算机研究生机试真题
    #include <iostream>
    #include <algorithm>
    #include <stdio.h>
    #include <string>
    #include <ctype.h>
    
    using namespace std;
    
    int main()  {
        int n, x, y, z;
        while(scanf("%d", &n) != EOF)   {
            scanf("%d%d%d", &x, &y, &z);
            int sa, sb, per = 0;
            for(int a = 1; a <= 9; a++) {
                for(int b = 0; b <= 9; b++) {
                    int m = a*10000+x*1000+y*100+z*10+b;
                    int re = m % n;
                    int tem = m / n;
                    if(re == 0 && tem > per)  {
                        per = tem;
                        sa = a; sb = b;
                    }
                }
            }
            if(per != 0)    {
                printf("%d %d %d
    ", sa, sb, per);
            }
            else{
                printf("%d
    ", per);
            }
    
        }
    
    
        return 0;
    }

    注意观察题目给出样例最后一个是0,证明单价为0的时候不要输出总价的开头和结尾

    这个题目没有说明,但是自己要注意看

  • 相关阅读:
    TCP与UDP的差别以及TCP三次握手、四次挥手
    MAC帧格式、IPV4数据报格式、TCP报文格式、UDP数据报格式
    维特比算法(Viterbi)-实例讲解(暴力破解+代码实现)
    对ajax的理解
    get与post两种方式的优缺点
    什么是Ajax和JSON,它们的优缺点
    浅谈一下如何避免用户多次点击造成的多次请求
    ajax是什么?
    同步和异步的区别?
    如何解决跨域问题
  • 原文地址:https://www.cnblogs.com/QingHuan/p/7106179.html
Copyright © 2011-2022 走看看