时间限制:1 秒

内存限制:32 兆

特殊判题:否

提交:2691

解决:1432

题目描述:

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 <stdio.h>

#define N 100

int main(void)
{
int n, i, j, num;
int x, y, z, xyz0; while (scanf("%d", &n) != EOF)
{
scanf("%d%d%d", &x, &y ,&z);
xyz0 = x*1000 + y*100 +z*10; int find = 0;
for (i=9; i>0; i--)
{
for (j=9; j>=0; j--)
{
num = i*10000 + xyz0 + j;
if (num % n == 0)
{
printf("%d %d %d\n", i, j, num/n);
find = 1;
break;
}
}
if (find == 1)
break;
}
if (find == 0)
printf("0\n");
} return 0;
}
/**************************************************************
Problem: 1036
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/

九度OJ 1036:Old Bill (老比尔) (基础题)的更多相关文章

  1. 九度OJ 1261:寻找峰值点 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:500 解决:37 题目描述: 给定一个整数序列,该整数序列存在着这几种可能:先递增后递减.先递减后递增.全递减.全递增. 请找出那个最大值的 ...

  2. 九度OJ 1158:买房子 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1801 解决:1096 题目描述: 某程序员开始工作,年薪N万,他希望在中关村公馆买一套60平米的房子,现在价格是200万,假设房子价格以每 ...

  3. 九度OJ 1083:特殊乘法 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4114 解决:2809 题目描述: 写个算法,对2个小于1000000000的输入,求结果. 特殊乘法举例:123 * 45 = 1*4 + ...

  4. 九度OJ 1065:输出梯形 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5379 解决:2939 题目描述: 输入一个高度h,输出一个高为h,上底边为h的梯形. 输入: 一个整数h(1<=h<=1000 ...

  5. 九度OJ 1064:反序数 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3758 解决:2773 题目描述: 设N是一个四位数,它的9倍恰好是其反序数(例如:1234的反序数是4321) 求N的值 输入: 程序无任 ...

  6. 九度OJ 1063:整数和 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3456 解决:2254 题目描述: 编写程序,读入一个整数N. 若N为非负数,则计算N到2N之间的整数和: 若N为一个负数,则求2N到N之间 ...

  7. 九度OJ 1062:分段函数 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3306 解决:1952 题目描述: 编写程序,计算下列分段函数y=f(x)的值. y=-x+2.5; 0<=x<2 y=2-1. ...

  8. 九度OJ 1052:找x (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:7335 解决:3801 题目描述: 输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数 ...

  9. 九度OJ 1046:求最大值 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:9861 解决:4013 题目描述: 输入10个数,要求输出其中的最大值. 输入: 测试数据有多组,每组10个数. 输出: 对于每组输入,请输 ...

  10. 九度OJ 1031:xxx定律 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6058 解决:3816 题目描述:     对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数 ...

随机推荐

  1. HDU 1025 Constructing Roads In JGShining's Kingdom[动态规划/nlogn求最长非递减子序列]

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  2. codevs——1576 最长严格上升子序列(序列DP)

     时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给一个数组a1, a2 ... an,找到最长的上升降子序列 ...

  3. 怎样在 CentOS 7.0 上安装和配置 VNC 服务器

    这是一个关于怎样在你的 CentOS 7 上安装配置 VNC 服务的教程.当然这个教程也适合 RHEL 7 .在这个教程里,我们将学习什么是 VNC 以及怎样在 CentOS 7 上安装配置 VNC ...

  4. HDU 3549 Flow Problem (dinic模版 && isap模版)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 题意: 给你一个有向图,问你1到n的最大流. dinic模版 (n*n*m) #include ...

  5. lock与monitor的区别

    1.Lock 只能对引用对象加锁 Lock锁定区间内可以对锁定值修改而不发生运行时错误,通常也会采用此种修改方式.这种方式又有点类同于使用Monitor.Wait取得资源,并对这个资源进行操作. 用法 ...

  6. 【spring cloud】对接口调用者提供API使用的安全验证微服务【这里仅通过代码展示一种设计思想】【后续可以加入redis限流的功能,某段时间某个IP可以访问API几次】

    场景: 公司的微服务集群,有些API 会对外提供接口,供其他厂商进行调用.这些公开的API接口,由一个OpenAPI微服务统一提供给大家. 那么所有的调用者在调用公开API接口的时候,需要验证是否有权 ...

  7. 【IntelliJ Idea】idea快速创建maven spring项目

    想试试AOP在spring的web项目上的使用情况,所以想尽快使用idea快速的搭建一个spring的web项目,当然,是maven管理的项目 步骤如下: 1.打开idea 左上角file---> ...

  8. mysql count(*) 和count(1)区别

    count *更快, 不要加where,否则同count(1)效率相同 sql语句对大小写不敏感,关键字一般大写,其他小写, count(*)不加where,mysql会直接返回总条数,因为mysql ...

  9. CSS 属性选择器的深入挖掘

    CSS 属性选择器,可以通过已经存在的属性名或属性值匹配元素. 属性选择器是在 CSS2 中引入的并且在 CSS3 中得到了很好拓展.本文将会比较全面的介绍属性选择器,尽可能的去挖掘这个选择器在不同场 ...

  10. 简单便捷的纯PHP网盘程序 Veno File Manager 2.6.3(VFM2)

    体验过很多国外网盘程序,例如:Owncloud.Bedrive.YetiShare.XFilesharing.uCloud.Cloudshare 等等,诸如此类,VFM2与这些臃肿的商用或非商用来的程 ...