天天看點

度小滿金融2020/9/20筆試

/*塗色
時間限制: 1000MS
記憶體限制: 65536KB
題目描述:
小A正在學畫畫,現在,線稿已經畫好了,隻剩下塗色部分了。但是小A發現,他的顔料不夠了。每一塊顔料能塗一個色塊,
每一個色塊的顔色是事先決定好了的。 由于顔料不夠,小A隻能盡其所能來塗色。
如果一個色塊沒有了顔料,就不能塗色。現在,給你畫中需要的色塊顔色,和小A現在手上有的顔料,請你計算小A能塗多少個色塊。

輸入描述
輸入包含兩個字元串,都僅包含大寫字母,每一種字母代表一種顔色。 第一個字元串S代表小A手上的顔料,第二個字元串T代表畫需要的顔料。

1≤|S|,|T|≤1000

輸出描述
輸出包含一個數,即最多能塗多少個色塊。

樣例輸入
AAB
ABC
樣例輸出
2

提示
小A擁有兩個A顔料,一個B顔料,用了一個A顔料一個B顔料,總共塗了兩個色塊。

*/

//第一題
//AC100%
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
	string S, T;
	cin >> S;
	cin >> T;
	map<char, int> mp1, mp2;
	for (auto ch : S) {
		mp1[ch]++;
	}
	for (auto ch : T) {
		mp2[ch]++;
	}
	int res = 0;
	for (auto it = mp2.begin(); it != mp2.end(); it++) {
		if (it->second <= mp1[it->first]) {
			res += it->second;
		}
		else {
			res += mp1[it->first];
		}
	}
	cout << res << endl;
	return 0;
}

//第二題:相似字元串
//通過:91%(不知道為什麼沒通過。。。)
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

bool check(string& s)
{
	int len = s.size();
	if (len % 3) return false;
	if (len == 3) return true;
	string s1 = s.substr(0, 3), s2 = s.substr(3, 3);
	vector<char> same;
	for (auto ch1 : s1) {
		for (auto ch2 : s2) {
			if (ch1 == ch2) {
				same.push_back(ch1);
			}
		}
	}
	if (same.size() < 2) return false;
	map<char, int> mp;
	for (auto ch : same) {
		mp[ch]++;
	}
	for (int i = 6; i < len; i += 3) {
		map<char, int> t = mp;
		int count = 0;
		for (int j = i; j < i + 3; j++) {
			if (t[s[j]] > 0) {
				count++;
				t[s[j]]--;
			}
		}
		if (count < 2) return false;
	}
	return true;
}

int main()
{
	int n;
	cin >> n;
	vector<string> vs;
	string tmp;
	while (n--) {
		cin >> tmp;
		vs.push_back(tmp);
	}
	for (auto val : vs) {
		if (check(val)) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}