快手2020春季实习生及校招补招程序B卷

四道搞定两道,悬。
在这里插入图片描述
在这里插入图片描述

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

void kuoHao(string str, int& legal, int& left, int& right) {
	for (auto ch : str) {
		if (ch == '(')
			left++;
		if (ch == ')') {
			if (left > 0) {
				left--;
				legal++;
			}
			else
				right++;
		}
	}
}

int main() {
	string str;
	cin >> str;
	int legal = 0, left = 0, right = 0;
	kuoHao(str, legal, left, right);
	cout << legal << " " << left << " " << right << endl;
	return 0;
}

在这里插入图片描述
在这里插入图片描述
这题直接用sort还报错了,C++11不支持???神奇

#include <iostream>
#include <vector>
#include <algorithm>
#include <windows.h>
using namespace std;

//bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
//	return a.first.first - a.first.second > b.first.first - b.first.second;
//}

void mySort(vector<pair<pair<int, int>, int>>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		pair<pair<int, int>, int> myMax = vec[i];
		int position = i;
		for (int j = i + 1; j < vec.size(); j++) {
			if (myMax.first.first - myMax.first.second < vec[j].first.first - vec[j].first.second) {
				myMax = vec[j];
				position = j;
			}
		}
		pair<pair<int, int>, int> temp = vec[i];
		vec[i] = vec[position];
		vec[position] = temp;
	}
}

vector<int> WaitInLine(vector<int>& a, vector<int>& b) {
	// write code here
	vector<int> result;
	vector<pair<pair<int, int>, int>> vec;
	for (int i = 0; i < a.size(); i++)
		vec.push_back(pair<pair<int, int>, int>({ a[i], b[i] }, i + 1));
	//sort(vec.begin(), vec.end(), cmp);
	mySort(vec);
	for (auto n : vec)
		result.push_back(n.second);
	return result;
}

int main() {
	vector<int> a = { 8,9,7 };
	vector<int> b = { 5,8,3 };
	vector<int> result = WaitInLine(a, b);
	for (auto n : result)
		cout << n << " ";
	cout << endl;
	system("pause");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值