描述
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.
示例1
输入:
72
6 7 9
5
2 3 7
78
0 0 5
复制
输出:
3 2 511
9 5 18475
0

代码

#include<iostream>
#include<cstdio>using namespace std;bool check1(int n) {//检查n是否刚好五位数int len = 0;while (n) {len++;n /= 10;}if (len == 5) return true;else return false;
}bool check2(int n, int x, int y, int z) {n /= 10;if (n % 10 != z) return false;else {n /= 10;if (n % 10 != y) return false;else {n /= 10;if (n % 10 != x) return false;else {n /= 10;if (n == 0) return false;}}}return true;
}int main() {int N, x, y, z;int a, b;//分别代表最高位和最低位while (scanf("%d", &N) != EOF) {scanf("%d%d%d", &x, &y, &z);int i;for (i = 99999; i > 0; i--) {if (check1(N * i) && check2(N * i, x, y, z)) {int sum = N * i;b = sum % 10;a = sum / 10000;printf("%d %d %d\n", a, b, i);break;}}if (i == 0) printf("0\n");}return 0;
}

枚举法|Old Bill相关推荐

  1. 算法:枚举法---kotlin

    枚举法:效率低,循环所有的情况,找到正确答案 用于解决数学问题,还是很简单的. 比如,奥数里面: 算 法 描 述 题X题=题题题题题题 其中 算法描述题每一个为一个数字,请写出正确的数字. ok,我们 ...

  2. c语言 3个人比饭量大小,OpenJudge计算概论-比饭量【枚举法、信息数字化】

    /*====================================================================== 比饭量 总时间限制: 1000ms 内存限制: 655 ...

  3. 开灯变形问题(枚举法)

    一.问题描述 一排有N盏灯.事先给定每盏灯的初始状态(开着或关着),你的任务是计算出至少要切换多少盏灯的状态(把开着的关掉,或把关着的打开),使得这N盏灯交替地打开和关闭. Input 输入文件中有多 ...

  4. c语言穷举算法 枚举法,c语言枚举法 穷举法 ppt课件

    枚举法 穷举法 笨人之法 把所有可能的情况一一测试 筛选出符合条件的各种结果进行输出 分析 这是个不定方程 三元一次方程组问题 三个变量 两个方程 x y z 1005x 3y z 3 100设公鸡为 ...

  5. 00002-两数之和-leetcode-1.暴力法(枚举法),2.哈希表法,目前更新了枚举法

    两数之和 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/two-sum 著作权归领扣网络所有.商业转载请联系官方授权,非商业转载请注明出处. ...

  6. c语言枚举法求满射函数,实变函数论讲义

    第1章 集合与点集 实变函数论作为现代分析数学的基础,其知识结构是建立在集合论之上的.集合论产生于19世纪70年代,由德国数学家康托尔(Cantor)创立,它是整个现代数学的开端及逻辑基础.作为本科教 ...

  7. 字符串匹配——枚举法

    字符串匹配--枚举法 给定主串T和模式串P,返回P在T中首次出现的位置,如果P不存在于T中,返回-1. 这样的问题就是字符串匹配问题,这里先给出枚举法的思想. 设主串T的长度为n,模式串P的长度为m. ...

  8. 什么叫枚举法_四年级:美妙数学之“巧用枚举法”1(0202四)

    美妙数学天天见 每天进步多一点 亲爱的小朋友,你好!我是朱乐平数学名师工作站的赵桂华老师,来自重庆市沙坪坝区西永第一小学. 准备好了吗?我们开始吧! 聪明的小朋友,你愿意和天天一起动脑思考吗? 天天, ...

  9. 马虎的算式子 (枚举法)

    题意: ab*cde = adb*ce (abcde五个不同的数字,不包含0) 满足该式子的一共多少种 解法1(枚举法) 思路: 本题目中的恒等条件是:ab*cde = adb*ce 其中不定量的取值 ...

最新文章

  1. 零基础Java学习之类和对象
  2. 50万块钱,在哪个银行存钱最合适?
  3. javaee 中文帮助文档_大牛耗时三天整理的:微服务+Nginx+Kubernetes实战文档和面试题...
  4. SQL DATEADD (Transact-SQL)根据需要返回时间,
  5. Java学习日报—2021/11/18
  6. Servlet之过滤器详解
  7. Spring 事务 状态信息的创建、回滚、清理、提交
  8. Android 的网络编程
  9. 小凡的Python之路——启航
  10. 伯努利方程(压力与流量的关系)
  11. ENVI下Landsat8辐射定标与大气校正
  12. win10虚拟打印服务器,win10系统安装虚拟打印机的图文方法
  13. 最全的PS快捷键大全!
  14. Linux系统的上行和下行带宽的检测
  15. 【Android】手撸抖音小游戏潜艇大挑战
  16. 一文带你了解SpringMVC框架的基本使用(上)
  17. NJCTF writeup
  18. MySql在Springboot项目中报错errorCode 1045 ,state 28000
  19. 【洛谷】P1456 Monkey King
  20. 51Nod-2006 飞行员配对(二分图最大匹配,匈牙利算法)

热门文章

  1. HTML5 之 A 标签
  2. mysql读取modbus_modbus 功能码
  3. CISP——身份鉴别
  4. C# 去除字符串最后一个字符
  5. 主流前端-后端-数据库总结-后端框架篇
  6. 五个防护软件之间的对决,结局真不理想……
  7. linux下C的GBD调试学习笔记
  8. Microsoft COCO (Common Objects in Context) dataset - COCO Explorer
  9. sql修改某一个字段部分数据
  10. Day758.Redis主从同步与故障切换的坑 -Redis 核心技术与实战