习题2.3 old bill

描述
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.

#include <stdio.h>

int main() {
   
    int n, x,y,z,price = 0,a,b;
    while (scanf("%d %d %d %d", &n, &x,&y,&z) != EOF) {
    
    }
    for(int i = 1;i < 10;i++)
        for(int j = 0;j < 10;j++)
        {
   
            int t = i*10000+x*1000+y*100+z*10+j;
            if(t%n == 0 && t/n>price)
            {
   
                a = i;
                b = j;
                price = t/n;
            }
            
        }
        if(price == 0)
            printf("0");
        else
            printf("%d %d %d",a,b,price);
    return 0;
}

暴力遍历即可

相关推荐

  1. 27)4.8 习题

    2024-02-20 22:10:02       38 阅读
  2. C语言经典习题20

    2024-02-20 22:10:02       24 阅读
  3. python基础24(完结撒花)_习题总结

    2024-02-20 22:10:02       46 阅读
  4. 数据库——习题

    2024-02-20 22:10:02       49 阅读
  5. springboot习题

    2024-02-20 22:10:02       25 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-20 22:10:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-20 22:10:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-20 22:10:02       82 阅读
  4. Python语言-面向对象

    2024-02-20 22:10:02       91 阅读

热门阅读

  1. Python 实现Excel 文件合并

    2024-02-20 22:10:02       67 阅读
  2. 2024年刷题记录

    2024-02-20 22:10:02       57 阅读
  3. 懒汉单例设计模式与饿汉单例设计模式

    2024-02-20 22:10:02       37 阅读
  4. 【算法训练营】等式,道路升级(c++,python实现)

    2024-02-20 22:10:02       49 阅读
  5. C语言 判断当前存储大小端问题

    2024-02-20 22:10:02       44 阅读
  6. MDC 日志跟踪笔记

    2024-02-20 22:10:02       45 阅读
  7. 汽车研发与制造中英文对照

    2024-02-20 22:10:02       55 阅读
  8. C#面:.NET中所有类型的基类是什么

    2024-02-20 22:10:02       55 阅读
  9. HTML世界核心

    2024-02-20 22:10:02       43 阅读
  10. c编译器学习01:tcc、chibicc简介

    2024-02-20 22:10:02       44 阅读
  11. Docker Compose 的安装方

    2024-02-20 22:10:02       45 阅读
  12. 华纳云:Nginx的内存池如何实现,有哪些特点

    2024-02-20 22:10:02       49 阅读
  13. 【Vue3】defineExpose

    2024-02-20 22:10:02       57 阅读
  14. P14 前缀和原理和特点

    2024-02-20 22:10:02       51 阅读
  15. element-plus_message.js

    2024-02-20 22:10:02       50 阅读