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的时候不要输出总价的开头和结尾

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

  • 相关阅读:
    使用SAEPython在虾米网自动签到
    Python的SimpleHTTPServer
    人人控 40行python搭出来的远程控制程序 支持插件
    吐血解决python中文写入文件问题
    JavaScript 响应选中文字并获取
    对WPS的吐槽
    Powerful Sleep 笔记[如何睡得好]
    Python极轻量HTTP服务器&框架 Bottle
    打印二维数组
    电梯的测试用例
  • 原文地址:https://www.cnblogs.com/QingHuan/p/7106179.html
Copyright © 2011-2022 走看看