题干:1092 To Buy or Not to Buy (20 分)
- 题解:用了23分钟,做了满分。。。其实23分钟里面,读题和编码的过程都是很紧张的,都是需要消耗不少的时间的,读题的时间在5分钟以上人的压力已经很大了,编码的过程还有不少的细节要处理,应该花了10分钟左右,最恐怖的是调试的时候。。。。
- 但是这题值得借鉴到日后的考试里面的经验是编写的时候先从基础的例子开始。。。然后在调试的时候进一步的认识和完善程序
-
// A1092.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include <bits/stdc++.h> using namespace std; unordered_map<char, int> shop;// int main() { #ifndef ONLINE_JUDGE FILE* s; freopen_s(&s, "in.txt", "r", stdin); #endif // !ONLINE_JUDGE string a,b; cin >> a >> b; for (int i = 0; i < a.size(); i++) { shop[a[i]]++;//vs直接显示建立好的图结构 } int count = 0; int flag = true; for (int i = 0; i < b.size(); i++) {//debug if (shop[b[i]] > 0) {//debug b[i]的位置写成a[i]; shop[b[i]]--; }else if (shop.find(b[i]) == shop.end() || shop[b[i]] == 0) { flag = false; count++; } } if (flag) { cout << "Yes" << " " << a.size() - b.size(); } else { cout << "No" << " " << count; } return 0; }