蓝桥杯省赛14天夺奖冲刺营代码

数据结构基础-栈

编程6「小邋遢的衣橱」

#include 
#include 
using namespace std;
queueq1;
queueq2;

int main() {
	int n;
	char op[5];
	string name, s;
	cin >> n;
	while (n--) {
		cin >> op;
		if (op[0] == 'I') {
			cin >> name >> s;
			if (s[0] == 'V') {
				q1.push(name);
			} else {
				q2.push(name);
			}
		} else {
			cin >> s;
			if (s[0] == 'V') {
				q1.pop();
			} else {
				q2.pop();
			}
		}
	}

	while (q1.empty() != true) {
		cout << q1.front() << endl;
		q1.pop();
	}
	while (q2.empty() != true) {
		cout << q2.front() << endl;
		q2.pop();
	}
	return 0;
}

数据结构基础-散列表(Hash)

编程8「弗里的的语言」

#include 
#include 
using namespace std;

map mp;
string s;
int main() {
	int n;
	cin  >>  n;
	while (n--) {
		cin >> s;
		mp[s]++;
	}

	map::iterator it;

	for (auto it = mp.begin(); it != mp.end(); it++) {
		if (it->second > 1) {
			cout << it->first << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

 数据结构之排序算法

 编程9「排序」

#include 
#include 
using namespace std;

bool cmp (int a, int b) {
	return a > b;
}
int a[500010];

int main() {
	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	sort(a, a + n);
	for (int i = 0; i < n; i++)
		printf("%d ", a[i]);

	printf("\n");

	sort(a, a + n, cmp);

	for (int i = 0; i < n; i++)
		printf("%d ", a[i]);
}

编程 13 「算式问题」

#include 
#include 
using namespace std;

int main() {
	int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
	int cnt = 0;
	do {
		int a1 = a[0] * 100 + a[1] * 10 + a[2];
		int b = a[3] * 100 + a[4] * 10 + a[5];
		int c = a[6] * 100 + a[7] * 10 + a[8];

		if (a1 + b == c)
			cnt++;
	} while (next_permutation(a, a + 9));
	cout << cnt << endl;
}

 编程 14 「求值」

#include 
#include 
#include 
using namespace std;
setst;

bool check(int x) {
	st.clear();//切记每次要清除全部
	for (int i = 1; i <= sqrt(x); i++) {
		if (x % i == 0)
			st.insert(i), st.insert(x / i);
	}
	if (st.size() == 100)
		return true;
	return false;
}

int main() {
	for (int i = 10000; i <= 1000000; i++) {
		if (check(i)) {
			cout << i << endl;
			return 0;
		}
	}
}

编程 15  「既约分数」

#include 
using namespace std;

int gcd(int a, int b) {
	return a % b == 0 ?  b : gcd(b, a % b);
}


int main() {
	int cnt = 0;

	for (int i = 1; i <= 2020; i++)
		for (int j = 1; j <= 2020; j++)
			if (gcd(i, j) == 1)
				cnt++;

	cout << cnt << endl;
}

 编程 16「天干地支」

#include 
using namespace std;

int main() {
	string a[10] = {"jia", "yi", "bing", "ding", "wu", "ji", "geng", "xin", "ren", "gui"};
	string b[12] = {"zi", "chou", "yin", "mao", "chen", "si", "wu", "wei", "shen", "you", "xu", "hai"};

	int n;
	cin >> n;
	int a1 = (n - 4) % 10;
	int b1 = (n - 4) % 12;
	cout << a[a1] << b[b1] << endl;
	return 0;
}

你可能感兴趣的:(stl,蓝桥杯,c++)