0731科大讯飞笔试

在这里插入图片描述
在这里插入图片描述
贪心,AC

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

int main()
{
	int money_count[5];
	int value[5] = { 1,5,10,50,100 };
	int input;
	for (int i = 0; i<5; i++)
	{
		cin >> money_count[i];
	}
	int k;
	cin >> k;
	//贪心,尽量用面额大的
	int count = 0;
	for (int i = 4; i >= 0; i--)
	{
		int c = min(k / value[i], money_count[i]);
		k -= c*value[i];
		count += c;
	}
	if (k>0)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << count << endl;
	}
	system("pause");
	return 0;
}

在这里插入图片描述
不知道为什么,只通过了83.3%

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int x_a1, y_a1, x_a2, y_a2, x_b1, y_b1, x_b2, y_b2;
	cin >> x_a1;
	cin >> y_a1;
	cin >> x_a2;
	cin >> y_a2;
	cin >> x_b1;
	cin >> y_b1;
	cin >> x_b2;
	cin >> y_b2;
	if (x_a1 <= x_b1&&x_a2 >= x_b2&&y_a1 <= y_b1&&y_a2 >= y_b2)
		cout << 0 << endl;
	else if (x_b1 <= x_a1&&x_b2 >= x_a2&&y_b1 <= y_a1&&y_b2 >= y_a2)
		cout << 0 << endl;
	else if (max(x_a1, x_b1) <= min(x_a2, x_b2) && max(y_a1, y_b1) <= min(y_a2, y_b2))
		cout << 1 << endl;
	else
		cout << 0 << endl;


	system("pause");
	return 0;
}

在这里插入图片描述
在这里插入图片描述
AC

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int my_atoi(string&s)
{
	int flag = 0;//表示是否为负数
	int res = 0;
	int count = 0;
	for (int i = 0; i<s.size(); i++)
	{
		if (s[i] >= '0'&&s[i] <= '9')
			count++;
	}
	for (int i = 0; i<s.size(); i++)
	{
		if (s[i] == '-')
			flag = 1;
		if (s[i] >= '0'&&s[i] <= '9')
		{
			if (count>0)
			{
				res += (int)pow(10, count - 1)*(s[i] - '0');
				count--;
			}

		}
	}
	if (flag == 1)
		res *= -1;
	return res;

}
int main()
{
	string s;
	getline(cin, s, '\n');
	int res = my_atoi(s);
	cout << res << endl;

	system("pause");
	return 0;
}

在这里插入图片描述
这题后来才知道是二路快排,当时没想到,所以只写了快排,只过了60%(暂时没打算看二路快排)

#include<iostream>
#include<vector>
using namespace std;
int partition(vector<int>&a,int low,int high)
{
	while (low < high)
	{
		while (low < high&&a[low] <= a[high])high--;
		swap(a[low],a[high]);
		while (low < high&&a[low] <= a[high])low++;
		swap(a[low], a[high]);
	}
	return low;
}
void quickSort(vector<int>&a, int low, int high)
{
	if (low < high)
	{
		int pivot = partition(a, low, high);
		//打印过程
		for (int i = 0; i < a.size(); i++)
		{
			cout << a[i] << " ";
			
		}
		cout << endl;
		quickSort(a, low, pivot - 1);
		quickSort(a, pivot + 1,high);
	}
}
int main()
{
	int n;
	cin >> n;
	vector<int>a(n, 0);
	for (int i = 0; i<n; i++)
	{
		cin >> a[i];
	}
	//快速排序
	quickSort(a, 0, a.size() - 1);



	system("pause");
	return 0;
}
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页