算法每日一题——08.04

codeforces1388a
最小的三个nearly prime是6 10 14,所以输入的数字只有大于30才可以。

#include<iostream>

using namespace std;

int main()
{
	int count;
	cin >> count;
	while (count)
	{
		int input;
		cin >> input;
		if (input <= 30)
			cout << "No" << endl;
		else
		{	
			cout << "Yes" << endl;
			int out = input - 30;
			if (out != 6 && out != 10 && out != 14)
				cout << 6 << " " << 10 << " " << 14 << " " << out << endl;
			else
				cout << 6 << " " << 10 << " " << 15 << " " << (out - 1) << endl;
		}
		count--;
	}
}

第二题

codeforces
A




#include<iostream>
using namespace std;
int main()
{
	int count;
	cin >> count;
	while (count)
	{
		int x, y, z;
		cin >> x >> y >> z;
		if (x == y && z <= x)
		{
			cout << "Yes" << endl << x << " " << z << " " << z << endl;
		}
		else if (x == z && y <= x)
		{
			cout << "Yes" << endl << x << " " << y << " " << y << endl;
		}
		else if (y == z && x <= y)
		{
			cout << "Yes" << endl << y << " " << x << " " << x << endl;
		}
		else
			cout << "No" << endl;
		count--;
	}
	return 0;
}

第三题

B
读入数据之后,只要判断当前输入的值是否已经出现,如果没有出现,则将其加到答案的最后位置,如果已经出现,则不进行添加,直到将输入全部读入。

#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t)
	{
		int n;
		int input;

		cin >> n;
		int ans[50];
		int max_index = -1;
		for (int i = 0; i < 2 * n; i++)
		{
			cin >> input;
			bool flag = false;
			for (int i = 0; i <= max_index; i++)
			{
				if (input == ans[i])
				{
					flag = true;
					break;
				}
			}
			if (flag == false)
			{
				ans[++max_index] = input;
			}
		}
		for (int i = 0; i <= max_index; i++)
			cout << ans[i] << " ";
		cout << endl;
		t--;
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值