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.

样例输入

72
6 7 9
5
2 3 7
78
0 0 5

样例输出

3 2 511
9 5 18475
0

我的代码

#include <bits/stdc++.h>
using namespace std;int main(){int x,y,z,n;cin >> n;cin >> x >> y >> z;int a,b,sum = 0;int single = 0;int flag = 0;for(a = 9;a >=1; a --){for(b = 9;b >=0; b --){sum = a *10000 + x * 1000 + y *100 + z * 10 + b;if(sum % n == 0){single = sum / n;flag = 1;cout << a << " " << b << " " << single << endl;goto here;}}}
here:if (flag == 0) {cout << "0" << endl;}return 0;
}

思路

暴力枚举求解,从9往下循环就避免了比较最贵价格的步骤,存在的可能一经发现必为最贵的情况,直接输出即可。

Old Bill(上海交通大学复试上机题)相关推荐

  1. 北京理工大学2000年复试上机题

    北京理工大学2000年复试上机题 一个数如果恰好等于它的各因子(该数本身除外)子和,如: 6=3+2+1,则称其为"完数":若因子之和大于该数,则称其为"盈数" ...

  2. 浙江工商大学20复试上机题之月利率

    浙江工商大学20复试上机题之月利率 Problem Description   为了早日实现买房娶媳妇的梦想,小明在攒够房子的首付款后一次性地向银行贷款借了a元,并约定分b个月还清.如果银行要求每月还 ...

  3. 历年北京理工大学复试上机题

    历年北京理工大学计算机复试(上机+专业综合): http://blog.csdn.net/u014552756/article/details/78506072 2000年北理复试上机题 2001年北 ...

  4. 北京理工大学复试上机题汇总

    秉承前人精神,祝学弟学妹们顺利上岸!!!!! (00-14和16-17是我转载的别的博主的,15.18和19是我的原创.题意大都描述正确,代码只具有一定参考性,希望大家都自己实现一下) 历年北京理工大 ...

  5. 北航计算机2014复试上机题,北航计算机系考研复试上机真题及答

    北航计算机系考研复试上机真题及答 (29页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 19.90 积分 Kao400.com 出品 侵权必究 北京航空航 ...

  6. 南大软件工程2019考研复试上机题+个人答案

    最近在准备南大软工的复试,正好把自己做的上机真题的解贴出来,希望可以帮助到对这道题有疑惑的同学.因为给自己限制了时间,所有没有做优化,望见谅. 题目:给一个字符串 由RGB(红绿蓝)3种字母组成 1. ...

  7. 牛客复试上机题 日期问题:

    对于日期类问题重要的是首先需要将每个月的日期记录下来以及重要的处理闰年的问题,每个月的日期记录下来可以用一个二维数组从第一维记录月份第二维记录是否是闰年即像这样记录 int date[13][2] = ...

  8. 2018复旦大学计算机硕士招生复试上机题(2)-解一元一次方程

    题目要求: 解方程,给定一个字符串,代表一个一元一次方程.如果有解求解,输出格式"x=数字",如果解的个数无穷,输出 "infinite solutions". ...

  9. 北邮OJ 102. 最远距离 北邮2012网研院复试上机题

    102. 最远距离 时间限制1000 ms     内存限制 65536 KB     题目描述 正义的伙伴褋祈和葬仪社的机器人Fuyuneru正在被邪恶的GHQ部队追杀.眼看着快要逃不掉了,祈就把重 ...

最新文章

  1. 最近做手机端,GPS,微信QQ分享总结的问题
  2. 影响堪比登月!谷歌等设计DL新方式让神经网络无限深无限窄
  3. Silverlight测试——利用Ranorex实现数据驱动测试
  4. Android Studio停留在“Indexing paused due to batch update”的解决方案
  5. 带有.rdlc报表的项目发布需要注意的问题
  6. PHP免费的空间www.hostinger.co.uk
  7. linux java 部署 生产环境
  8. String Problem(HDU-3374)
  9. 在一起计时器_奇妙物理·高中篇:打点计时器基本介绍
  10. linux 配置 MP3 RMVB 解码器
  11. 神奇宝贝HTML游戏代码,《我的世界》神奇宝贝召唤神兽指令 各神兽召唤代码大全...
  12. k近邻算法_K近邻算法(一)
  13. YUV和RGB格式分析
  14. 转:驳Moxie关于Web3中“去中心化”、“服务器”和“密码学”的观点
  15. 免费学python的手机软件_可以免费学习编程算法app
  16. 少儿编程入门应该从机器人Scratch编程开始
  17. 2017. 圆周排列
  18. 语义分析(semantic analysis)概述
  19. Maven 导入 com.sun.javadoc包
  20. 高新兴 ME3630-W 4G 模块 Android 平台适配

热门文章

  1. 树莓派nginx+php+MariaDB配置
  2. 用SQL Developer 解决Oracle密码过期the password has expired
  3. 惠惠软件|经验分享:路由器如何设置对接入无线设备的控制
  4. round函数python逗号后不要了吗_Python 中关于 round 函数的小坑
  5. “购物返现积分兑换”——区块链思维的购物返利方式
  6. leetcode 38.外观数列
  7. 大型网站技术架构 读书笔记 (八) 固若金汤:网站的安全架构
  8. python-cookie http.cookiejar用法
  9. PC端聊天机器人界面(html实现)
  10. 五、XMLTomcatHttp协议