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

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

  • 相关阅读:
    随机变量与概率分布
    概率知识归纳
    随机生成&部门匹配
    SudokuGame 记软工第二次作业
    从0到1的开发,社交App 完成
    Emmm,从删库到跑路系列之.......Root权限的重要性
    处理AsyncTask的内存泄漏问题
    关于服务器端的Json文件的接收,踩了一早上的坑的问题
    一些安卓模拟器的IP问题和getOutputStream();关于connect();的函数异常的问题
    擦擦博客的灰------开始毕设,社交应用开发 之 前期准备
  • 原文地址:https://www.cnblogs.com/QingHuan/p/7106179.html
Copyright © 2011-2022 走看看