题目链接

题目描述

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.

在祖父的文件中发现了一张账单。72只火鸡$_679_,显然代表这些火鸡的总价格的数字的第一个和最后一个数字在这里被空白代替(表示_),因为它们已经褪色,难以辨认。那两个褪色的数字是什么?一只火鸡的价格是多少?我们打算编写一个程序来解决一般情况下的上述问题。N只火鸡$XYZ,火鸡的总数N介于1和99之间。总价原本是五位数字,但我们只看到中间三位。我们假设第一个数字是非零,一只火鸡的价格是美元的整数,所有火鸡的价格都是一样的。给定N, X, Y和Z,编写一个程序来猜测这两个褪色的数字和原始价格。如果有一个以上的候选原始价格,输出最昂贵的。也就是说,该程序将报告这两个褪色的数字和每只火鸡的最高价格。

输入描述

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_.

输入的第一行包含一个整数N (0<N<100),代表火鸡的数量。下一行是原始价格$_XYZ_的三位十进制数字X、Y和Z,用空格分隔。

输出描述

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

思路

循环遍历两个数字找到可能的整数结果,因为取最贵的原始价格,直接从9倒序遍历到出现结果即可。

代码

#include<bits/stdc++.h>int main(){int num;int x,y,z;int sum;while(scanf("%d\n%d %d %d",&num,&x,&y,&z)!=EOF){int a,b,price=0; //账单不见的两位数字 单价for(int i=9;i>0;i--){for(int j=9;j>=0;j--){sum = i*10000+x*1000+y*100+z*10+j;if(sum%num==0){a = i;b = j;price = sum/num;break;}//if}//forif(price){printf("%d %d %d\n",a,b,price);break;}}//forif(!price){printf("0\n");}}//while    return 0;
}

【c/c++】Old Bill相关推荐

  1. 【牛客】Old Bill(C语言)

    题目描述 Among grandfather's papers a bill was found.     72 turkeys $_679_     The first and the last d ...

  2. 【C 语言】内存管理 ( 动态内存分配 | 栈 | 堆 | 静态存储区 | 内存布局 | 野指针 )

    相关文章链接 : 1.[嵌入式开发]C语言 指针数组 多维数组 2.[嵌入式开发]C语言 命令行参数 函数指针 gdb调试 3.[嵌入式开发]C语言 结构体相关 的 函数 指针 数组 4.[嵌入式开发 ...

  3. 【C 语言】编译过程 分析 ( 预处理 | 编译 | 汇编 | 链接 | 宏定义 | 条件编译 | 编译器指示字 )

    相关文章链接 : 1.[嵌入式开发]C语言 指针数组 多维数组 2.[嵌入式开发]C语言 命令行参数 函数指针 gdb调试 3.[嵌入式开发]C语言 结构体相关 的 函数 指针 数组 4.[嵌入式开发 ...

  4. java和其他语言相比 特点,【单选题】与其他面向对象语言相比,Java语言突出的特点是:...

    [单选题]与其他面向对象语言相比,Java语言突出的特点是: 更多相关问题 55 A fresh B soft C deep D warm 13 Many economists have given ...

  5. *【POJ - 2796】 Feel Good (前缀和优化+单调栈维护)

    题干: Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12409   Accepted: 3484 Ca ...

  6. 【半年总结】---凤凰涅槃,历久弥新

    指缝很宽,时间很瘦.日子总是像从指尖流过的细沙,在不经意间悄然滑落.那些往日的旧事,在似水流年的荡涤 下随波轻轻地逝去,而留下的欢乐和笑靥总在记忆深处历久弥新. 回顾过去的半年,想用几个简单的关键词来 ...

  7. UVA497 Strategic Defense Initiative【LIS+DP】

    "Commander! Commander! Please wake up commander!"     "- mmmph. What time is it?" ...

  8. 【每日英语】英语语法

    [每日英语]英语语法 标签(空格分隔):[everyday] 英语语法 文章目录 英语语法 0. 绪论 0.1 名词短语的功能 0.2 名词短语的构造 1. 名词 1.1 名词的定义与分类 1.1.1 ...

  9. Spring源码解析【完整版】--【bilibili地址:https://www.bilibili.com/video/BV1oW41167AV】

    [本文为bilibili视频雷丰阳的Spring源码解析的完整版总结文章,其中文章前面大部分为他人博文的搬运,后面补充了其未总结的部分] 一.Java的注解 1. 注解的概念 注释:用文字描述程序,给 ...

最新文章

  1. python中文叫什么意思-python中文叫什么
  2. Spark _12_每个网址的每个地区访问量 ,由大到小排序
  3. windows和linux共同分区格式,Linux和Windows共存的模式下分区要小心
  4. 【HDU - 1045】Fire Net (dfs 或二分图)
  5. 送书 | 推荐一个可能是最全的Venn图一站式绘制工具
  6. java获取url的参数page返回数值page计算_Java常用代码汇总,建议背会
  7. 计划任务 crontab、at
  8. vscode-icons插件使用
  9. Mysql数据类型blob存储长度
  10. [ 原创 ]学习笔记-安卓虚拟机终于达到最佳状态了
  11. 关于unity打包apk在手机上安装失败(-108)
  12. 12306个人敏感信息泄露
  13. 钉钉打卡显示服务器忙,钉钉系统繁忙请稍后再试
  14. 弹弹弹,弹走鱼尾纹的弹出菜单(vue)
  15. 疑似小米汽车全车设计效果图曝光 小米Logo上车
  16. 开始愉快的学习编程了
  17. 使用UltraISO制作纯U盘引导,UEFI安装win10[单文件超过4G]
  18. 《中国计算机报 停刊,《中国计算机报》硬件之星“最具超值”产品:捷波J-865PEDA...
  19. 彻底卸载2345王牌输入法的方法
  20. 分布式存储能成为存储市场增长的主要驱动力

热门文章

  1. 【LeetCode】852. 山脉数组的峰顶索引(C++)
  2. 名帖230 张雨 行书《独游龙井方圆庵卷》
  3. java 1除以2_代码优化之整型除以2的指数并四舍五入
  4. JAVA 分配发票问题
  5. Java学习第二十七天<面向对象综合练习><猜拳游戏>
  6. apache benchmark 做接口压力测试
  7. 真是环境下阿里云RDS实例mysql性能优化-慢查询分析、优化索引和配置
  8. 侠客风云传ol未能连接服务器,《侠客风云传online》8月31日服务器数据互通公告...
  9. 数据传送指令----mov(笔记)ATT
  10. JS获取当前域名的顶级域名