Old bill

这是一个关于编程算法的问题,要求编写一个程序来解决类似旧账单上的问题。给定购买的火鸡数量N,以及账单上中间的三个数字X、Y和Z,程序需要找出缺失的第一和第五个数字,并计算出火鸡的单价。程序通过尝试所有可能的组合来找到使总价能被火鸡数量整除的数字,如果存在多个解决方案,则选择使单价最高的那个。输入包括火鸡数量和账单的中间三位数字,输出为缺失的两个数字和最高单价。
摘要由CSDN通过智能技术生成

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

#include<iostream>
#include<cstdio>
#include <stdio.h>
#include <stdlib.h>


using namespace std;


int main() {
	int n, x, y, z;
	while ((scanf("%d%d%d%d", &n, &x, &y, &z)) != EOF) {
		int i = 0, j = 0, num = 0, price = 0, mi = 0, mj = 0, total = 0;
		num += (1000 * x + 100 * y + 10 * z);
		for ( i = 1; i < 10; ++i) {
			for ( j = 0; j < 10; ++j) {
				total = (num + 10000 * i + j);
				if (total % n == 0) {
					mi = i;
					mj = j;
					
				}
			}
		}
		if (mi == 0 && mj == 0) {
			printf("0\n");
		}
		else {
			price = (num + 10000 * mi + mj) / n;
			printf("%d %d %d\n", mi, mj, price);
		}

	}
	return 0;
	}

在需要一直输入时可以使用:while((scanf("%d%d%d%d", &n, &x, &y, &z)) != EOF)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值