牛客网算法:邮票

题目描述

某人有8 角的邮票5 张,1 元的邮票4 张,1 元8 角的邮票6 张,用这些邮票中的一张或若干张可以得到多少中不同的邮资?

输入描述:

输出描述:

输出一行,表示题目所求。

示例1

输入

输出

#include <iostream>
#include <set>
using namespace std;

const int arr[3] = {8, 10, 18};

int main() {
	set<int> totalPrice;
	int i = 0;
	for (i = 0; i <= 5; i++) {
		for (int j = 0; j <= 4; j++) {
			for (int k = 0; k <= 6; k++) {
				if (i == 0 && j == 0 && k == 0) {
					continue;
				}
				totalPrice.insert(arr[0]*i+arr[1]*j+arr[2]*k);
			}
		}
	}
	cout << totalPrice.size() << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_32273417/article/details/87892294
今日推荐