度小满金融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; }
#笔试题目##度小满#